Last answered:

13 Jan 2024

Posted on:

18 Aug 2023

0

Task 1 - Solution to avoid the error

Here's my solution - at this stage.

First check if it's in our range cause there's no restriction on inputing only integers. It could be a string - causing an error.

AND! it should reduce the time of the program since it will first check for all the wrong answers (which are many), instead of going through our needed few.

Then check everything else.

 


user_input = input("Please, input an integer from 1 to 3\n>>> ")


if user_input != "1" and user_input != '2' and user_input != "3":
    print("The input is not valid. Please, try again")

elif int(user_input) == 1:
    print('one')
elif int(user_input) == 2:
    print('two')
elif int(user_input) == 3:
    print('three')

1 answers ( 0 marked as helpful)
Posted on:

13 Jan 2024

0

Value Error?

Submit an answer