"Invalid return" при много простичка задача

Задачата е следната:

Digit as Word

Description

Write a program that read a digit [0-9] from the console, and depending on the input, shows the digit as a word (in English).

  • Print “not a digit” in case of invalid input.
  • Use a switch statement.

Input

  • The input consists of one line only, which contains the digit.

Output

  • Output a single line - should the input be a valid digits, print the english word for the digits. Otherwise, print “not a digit” .

Constraints

  • The input will never be an empty line.

Sample tests

Input Output
-0.1 not a digit
1 one
9 nine
-9 not a digit
kek not a digit

А кодът който съм написал е:

a = input()

match a:

    case '1':

        print('one')

    case '2':

        print('two')

    case '3':

        print('three')

    case '4':

        print('four')

    case '5':

        print('five')

    case '6':

        print('six')

    case '7':

        print('seven')

    case '8':

        print('eight')

    case '9':

        print('nine')

    case _:

        print('not a digit')

Доста straight forward, и когато го рън-вам работи, но Judge дава инвалид ретърн, какъв е проблемът?

ами case ‘0’ ?

2 Likes

Case 0 липсваше, но нищо не променя. Оказа се че Judge май изобщо не разпознава match - case statements, направих го с if-ове и стана.

a = input()

if a == '0':

    print('zero')

elif a == '1':

    print('one')

elif a == '2':

    print('two')

elif a == '3':    

    print('three')

elif a == '4':      

    print('four')

elif a == '5':     

    print('five')

elif a == '6':      

    print('six')

elif a == '7':      

    print('seven')

elif a == '8':      

    print('eight')

elif a == '9':     

    print('nine') 

else:

    print('not a digit')
1 Like

Най-якото е като сам се оправиш и пребориш Judge-a :slight_smile:

3 Likes