Nov-21-2022, 10:32 PM
(This post was last modified: Nov-21-2022, 11:01 PM by rob101.
Edit Reason: added code
)
Okay, well you could do something like this:
Another way to do that, would be to include the
def get_int(n): try: n = int(n) return n except ValueError: return False while True: number = get_int(input("Number: ")) if number: # do whatever print(number, type(number)) else: print("Error in number input")But I've no doubt that it could be improved upon. e.g: the
if number:
fails. It does not class a zero as an integer.Another way to do that, would be to include the
input()
function:def get_int(prompt): n = input(prompt) try: n = int(n) return n except ValueError: return False while True: number = get_int("Number: ")
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein