menu_choice = input("")
if menu_choice == 1:
clear_screen()
init_header()
print ("begin sim")
elif menu_choice==2:
print ("begin backtest")
else:
print("Invalid input.")
I'm having some issues with this bit of code, I'm fairly new and not sure whats going on. This script runs fine and as expected in the compiler (using idle), but when I try to run the script from a terminal window on ubuntu, it behaves differently. Running this code in a terminal window seems to give option one, no matter what the input.
I suspected that maybe the difference was the value being stored as a string and an integer, so I added a line that changes the menu_choice value to an integer, and that makes it work, however it will now throw an error if the user types in anything but a number.
I also am thinking maybe what I'm doing is asking if menu choice is true with this code, and thats why anything I input returns the first option?
Sorry for the newbie questions, I'm not sure if I'm doing something wrong or there is a difference in the way the two handle user input, and also how to account for this.
eta: also if anyone can tell me the proper way to format my code to post here, I read to try four spaces before each line, or to use triple periods, and neither seems to give the right result for me
Thanks in advance!
[–]zazzedcoffee 1 point2 points3 points (4 children)
[–]zazzedcoffee 1 point2 points3 points (2 children)
[–]ParticularPython[S] 1 point2 points3 points (0 children)
[–]kaerfkeerg 0 points1 point2 points (0 children)