forked from psounis/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise02.py
More file actions
29 lines (25 loc) · 869 Bytes
/
exercise02.py
File metadata and controls
29 lines (25 loc) · 869 Bytes
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
def get_integer():
while True:
try:
user_input = input("Give integer: ")
if user_input[0] == "-":
st = user_input[1:]
if st == "":
raise ValueError("No digits entered!")
elif not st.isdigit():
raise ValueError("Wrong Input. Only digits please!")
x = -int(st)
else:
st = user_input
if st == "":
raise ValueError("No digits entered!")
elif not st.isdigit():
raise ValueError("Wrong Input. Only digits please!")
x = int(st)
except ValueError as v:
print(v)
except Exception as e:
print(e)
else:
return x
print(get_integer())