I started learning python 3 days ago and needed some help on my code...
i want to loop the "go_again" var to where it keeps running until the user enters "no", because right now it only runs once. My guess is that it needs a while loop, but how would i do that?
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 |
#Basic calculator #First python calculator #How to improve this??? name = str ( input ( "Hello please enter in your name: " )) print ( "Nice meeting you " + name) print ( "This is a very basic calculator that i've made. Hope you enjoy!" ) def calculator(): choose = str ( input ( "ADDITION(a), MULTIPLICATION(m), SUBTRACTION(s), DIVISION(d) " )) if choose = = 'a' : number1 = int ( input ( "Choose your first number: " )) number2 = int ( input ( "Choose your second number: " )) print (number1 + number2) elif choose = = 's' : number1 = int ( input ( "Choose your first number: " )) number2 = int ( input ( "Choose your second number: " )) print (number1 - number2) elif choose = = 'm' : number1 = int ( input ( "Choose your first number: " )) number2 = int ( input ( "Choose your second number: " )) print (number1 * number2) elif choose = = 'd' : number1 = int ( input ( "Choose your first number: " )) number2 = int ( input ( "Choose your second number: " )) print (number1 / number2) calculator() go_again = str ( input ( "Would you like to go again? Y/N " )) if go_again = = 'y' : calculator() #How to loop this??? elif go_again = = 'n' : print ( "Goodbye..." ) exit() |
User has been warned for this post. Reason: bad title description