can't seem to get this loop to work, it keeps looping back to the Binary Number Input. I'd like it to loop back to the menu selection. Sorry for the noob question I'm new to python and programming.
import sys
loop = 0
menu_Select = 0
for menu_Select in range(1,100):
#Display user options to the screen
print('*** Menu ***')
print('1. Convert to binary')
userMenu = input('What would you like to do [1,2,3,4]? ')
if userMenu != '1' and userMenu != '2' and userMenu != '3' and userMenu != '4':
print("Please enter either 1, 2, 3, or 4.")
elif userMenu == '4':
print('Goodbye.')
sys.exit(0)
elif userMenu == '1':
#Decimal to Binary convertion code
print('\n')
while loop < 1:
while True:
try:
user_Number = (int(input('Please enter number: ')))
except ValueError:
print('wrong')
else:
binary_num = []
while (user_Number > 0):
if user_Number % 2 != 0:
binary_num.append(1)
elif user_Number % 2 == 0:
binary_num.append(0)
user_Number = user_Number // 2
binary_num.reverse()
binary_display = ''.join(str(k) for k in binary_num)
print('Binary number: ',binary_display)
loop += 1
while True:loop to end?if userMenu != '1' and userMenu != '2' and userMenu != '3' and userMenu != '4':to check for undefined options. Either doif int(userMenu) in range(1,5):, or do the correspondingprintcommand in anelsestatement after the behavior for valid options is defined.breakto exit this loop. Why is that loop in the code anyway?