Oct-26-2022, 05:56 PM
hey guys,
so as a continuation of the previous thread - and taking my own code (as it is easier for me to comprehend) , how do you make sure an input is from the desired type ? (in this case - integer),
suppose the type is a different kind - how is it being accompanied with a message (suppose - "please enter an integer kind of number") and re-asking for an input...
base code:
so as a continuation of the previous thread - and taking my own code (as it is easier for me to comprehend) , how do you make sure an input is from the desired type ? (in this case - integer),
suppose the type is a different kind - how is it being accompanied with a message (suppose - "please enter an integer kind of number") and re-asking for an input...
base code:
import random RNumber = random.randint(1,10) user_input = int(input("please guess a number between 0 and 10: \n")) while user_input != RNumber: if user_input > RNumber: user_input = int(input("choose a lower number: \n")) elif user_input < RNumber: user_input = int(input("choose a higher number: \n")) print("the number you chose is correct (", RNumber, ")")