Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
loop until user enters no
#1
I started learning python 3 days ago and needed some help on my code...
#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()
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?

User has been warned for this post. Reason: bad title description
Reply


Messages In This Thread
loop until user enters no - by JohnnyFobby - Jan-22-2018, 02:39 AM
RE: Help - by j.crater - Jan-22-2018, 06:53 AM
RE: Help - by JohnnyFobby - Jan-22-2018, 07:12 AM
RE: Help - by j.crater - Jan-22-2018, 07:23 AM
RE: Help - by JohnnyFobby - Jan-22-2018, 07:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,107 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  Multiple user defined plots with secondary axes using for loop maltp 1 1,487 Apr-30-2022, 10:19 AM
Last Post: maltp
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,521 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  Looking for a way to loop until user enters from a list? PythonW19 7 3,431 Mar-21-2021, 08:56 PM
Last Post: PythonW19
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 2,965 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes
  Nested Loop for user input Ads 2 3,581 Dec-30-2019, 11:44 AM
Last Post: Ads
  Server infinite loop input from user tomislav91 1 4,245 May-23-2019, 02:18 PM
Last Post: heiner55
  Read from a file, get user input in a while loop lynden 8 4,168 Nov-05-2018, 12:31 PM
Last Post: lynden
  [Help] sorted() in while loop with user's input() {Screenshot attached} vanicci 5 4,038 Aug-04-2018, 08:59 PM
Last Post: vanicci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020