-
Notifications
You must be signed in to change notification settings - Fork 0
/
number.py
50 lines (41 loc) · 1.04 KB
/
number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# try:
# x = int(input("What's x? "))
# except ValueError:
# print("X is not an integer")
# else:
# print(f"x is {x}")
# allow user to insert the correct number
# while True:
# try:
# x = int(input("What's X? "))
# except ValueError:
# print("x is not an integer")
# else:
# break
# print(f"x is {x}")
# #myfunction
# def main():
# x = get_int()
# print(f"x is {x}")
# def get_int():
# while True:
# try:
# x = int(input("What's X? "))
# return x
# except ValueError:
# print("x is not an integer")
# main()
#myfunction and pass (silently ignore)
def main():
x = get_int("What's X? ")
print(f"x is {x}")
def get_int(prompt):
while True:
try:
x = int(input(prompt))
return x # you can avoid using x variable if you aren't goint to use it again
#return = int(input("What's X? "))
except ValueError:
# print("x is not an integer")
pass
main()