[Tutor] python help
John Weller
john at johnweller.co.uk
Sat Sep 12 13:56:07 EDT 2020
>
> I need to write a code that asks for a number between 5 and 25 and only allows
> integers and if a non integer is entered it needs to print 'you must enter an
> integer' or if it types a number less than 5 or more than 25, it needs to re-ask the
> original question until it gets an appropriate answer would it be better to form an
> else if or a range or is there a more effective function to put in my code? my first
> thought would be:
> print('Enter an integer between 5 and 25')howMany = input() limit(int(num,
> minimum = 5, maximum = 25) else ValueError
>
> if ValueError = print('Enter an integer between 5 and 25') or for howMany in
> range (5, 25) print(....
> or
> while howMany = (>=5, <=25): continue else return
>
> I can't seem to get to any usable code that makes sense to even me. And google,
> and my textbook aren't helpful with examples at all.
> Please suggest something that should be completely obvious to me Thank you!!
I'm sure that others will give you better advice than I can on the best way to structure your code but the way to check if a number is an integer is:
If number == int(number):
Print("Integer")
Else:
Print("Not integer")
More information about the Tutor
mailing list