Python Forum
Need help with the program its not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with the program its not working
#1
#!/usr/bin/env python3

# Simple Calculator

# Function to subtract
def subtract(x, y):
   return int(x) - int(y)

# Function to multiply
def multiply(x, y):
   return int(x) * int(y)

# Function to add
def add(x, y):
   return int(x) + int(y)

# Function to divide
def divide(x, y):
   return int(x) / int(y)

# Show a menu
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")

# ASk for user input
choice = input("Enter choice(1/2/3/4):")

# ASk for two numbers and Turn input strings to integers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

# Check the choice and send the values to the correct function
if choice == 1:
   print(num1,"+",num2,"=", add(num1,num2))

elif choice == 2:
   print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == 3:
   print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == 4:
   print(num1,"/",num2,"=", divide(num1,num2))
else:
   print("Invalid input")
i also need to know tha the answer would be to this question?



After fixing the function, test it using the numbers 10 and 46. What is the last line of the output?
Reply
#2
First of all, use Python tags when posting code. See the BBCode link for instructions on how to do that. I did it for you this time.

Second of all, we're not here to do your homework. You are going to have to show some effort. You tell us what is wrong with the program.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem: Once I cancel the process my program will start working! Hadad 0 1,660 Jul-24-2019, 04:09 PM
Last Post: Hadad
  Date Format Changing Program Not Working pyth0nus3r 2 4,741 Jan-28-2017, 10:34 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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