Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:20:47+00:00 2026-06-17T22:20:47+00:00

I am working on a calculator in python as one of my assignments for

  • 0

I am working on a calculator in python as one of my assignments for class (basic operations, addition, subtraction, multiplication, and division) I have a print menu from which the user can choose what operation they want to use… and then enter their integers and an print statement of what the answer is. My problem is that I need to repeat my initial input of what operation the user would like to execute. New to programming so any help is greatly appreciated.

Here is my code:

print ("1 = addition")
print ("2 = subtraction")
print ("3 = multiplication")
print ("4 = division")
print ("5 = Exit program\n")

x = int (input ("What operation would you like to perform?: ")) #prompts user for operation

if (x == 1): #if operation chose is addition then this line will exacute
  int1 = input ("Enter first integer: ")
  int1 = int (int1)
  int2 = input ("Enter second integer: ")
  int2 = int (int2)
  sum = int1 + int2
  print ("Sum is:", sum)

elif (x == 2): #if operation chose is subtraction then this line will exacute
  int1 = input ("Enter first integer: ")
  int1 = int (int1)
  int2 = input ("Enter second integer: ")
  int2 = int (int2)
  dif = int1 - int2
  print ("Difference is:", dif)

elif (x == 3): #if operation chose is multiplication then this line will exacute
  int1 = input ("Enter first integer: ")
  int1 = int (int1)
  int2 = input ("Enter second integer: ")
  int2 = int (int2)
  mult = int1 * int2
  print ("Multiplication is:", mult)

elif (x == 4): #if operation chose is division then this line will exacute
  int1 = input ("Enter first integer: ")
  int1 = int (int1)
  int2 = input ("Enter second integer: ")
  int2 = int (int2)
  div = int1 / int2
  print ("Division is: %.2f" % div)

elif (x == 5):
  print ("goodbye")
  quit()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:20:48+00:00Added an answer on June 17, 2026 at 10:20 pm

    You can split that code into a function:

    print "1 = addition"
    print "2 = subtraction"
    print "3 = multiplication"
    print "4 = division"
    print "5 = Exit program\n"
    
    def maths(choice):
        if choice == 1: #if operation chose is addition then this line will exacute
           int1 = input("Enter first integer:")
           int2 = input ("Enter second integer: ")
           sum = int1 + int2
           print "Sum is:", sum
    
        elif choice == 2: #if operation chose is subtraction then this line will exacute
           int1 = input("Enter first integer: ")
           int2 = input("Enter second integer: ")
           dif = int1 - int2
           print "Difference is:", dif
    
        elif choice == 3: #if operation chose is multiplication then this line will exacute
           int1 = input("Enter first integer: ")
           int2 = input("Enter second integer: ")
           mult = int1 * int2
           print "Multiplication is:", mult
    
        elif choice == 4: #if operation chose is division then this line will exacute
           int1 = input("Enter first integer: ")
           int2 = input ("Enter second integer: ")
           div = int1 / int2
           print "Division is: %.2f" % div
    
        elif choice == 5:
           print "goodbye"
           quit()
    
    while True: # "While True, repeat everything below":
        maths(input("What operation would you like to perform?: "))
    

    Edit: It seems you have stated that it’s python 2.7, so I cleaned the code for you.

    You do not need int(int1) and int(int2) because input() does not make the input a string. i.e:

    >>> number = input('Enter a number! ') # Let's say I put 5
    >>> print number
    5 # Notice it's not a string (no ' ')
    

    Whereas raw_input() would do:

    >>> number = raw_input('Enter a number! ')
    >>> print number
    '5' # 5 is a string, not an integer. And so int() would be required
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working tax calculator that I need to add one more piece
I have a calculator application in java swing, which is working properly with mouse
I'm trying to make a very simple calculator in python. I've made a working
I have this table and i can not make working the function calculator in
I'm working with Python and SQL and for my work I have to calculate
I am currently working on reimplementing some algorithm written in Java in Python. One
I have a python script that I am writing for a class assignment which
I have managed to get a UPS Shipping calculator working in PHP. I now
I have a python class to calculate the number of bits when they have
I'm trying to get a handle on multithreading in python. I have working code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.