-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
32 lines (28 loc) · 804 Bytes
/
helpers.py
File metadata and controls
32 lines (28 loc) · 804 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
30
31
32
def getInt(queryString):
while True:
value = input(queryString)
try:
return int(value)
except:
print(f"You must input an integer.")
def getFloat(queryString):
while True:
value = input(queryString)
try:
return float(value)
except:
print(f"You must input a number.")
def getIndex(length):
while length > 0:
value = getInt("Choose the desired index: ")
if -length <= value < length:
return value
else:
print("That is not a valid index.")
else:
raise ValueError
def printBinary(integer):
print(f"{integer} is")
print(f"\t{int(integer)} in base 10")
print(f"\t{bin(integer)} in binary")
print(f"\t{hex(integer)} in hex")