Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Code doesn't work!
#4
I fixed your word guessing game. Go back to your original thread while I fix this one

Here this should work. I tested it
# Program make a simple calculator that can add, subtract, multiply and divide using functions
 
# This function adds two numbers
def add(num1, num2):
   return num1 + num2
 
# This function subtracts two numbers
def subtract(x, y):
   return x - y
 
# This function multiplies two numbers
def multiply(x, y):
   return x * y
 
# This function divides two numbers
def divide(x, y):
   return x / y
 
 
 
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
 
# Take input from the user
choice = input("Enter choice(1/2/3/4):")
 
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
 
if choice == '1':
   print("%s + %s = %s" %(num1, num2, add(num1, num2)))
 
elif choice == '2':
   print("%s - %s = %s" %(num1, num2, subtract(num1,num2)))
 
elif choice == '3':
   print("%s * %s = %s" %(num1, num2, multiplay(num1, num2)))
 
elif choice == '4':
   print("%s / %s = %s" %(num1, num2, divide(num1, num2)))
else:
   print("Invalid input")
Reply


Messages In This Thread
Python Code doesn't work! - by the_entrepreneur - Apr-18-2019, 06:50 AM
RE: Python Code doesn't work! - by buran - Apr-18-2019, 07:14 AM
RE: Python Code doesn't work! - by the_entrepreneur - Apr-20-2019, 02:25 AM
RE: Python Code doesn't work! - by SheeppOSU - Apr-20-2019, 04:24 AM
RE: Python Code doesn't work! - by the_entrepreneur - Apr-20-2019, 07:14 AM
RE: Python Code doesn't work! - by SheeppOSU - Apr-20-2019, 08:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I can't for the life of me get this basic If statement code to work CandleType1a 8 448 May-21-2024, 03:58 PM
Last Post: CandleType1a
  Extending list doesn't work as expected mmhmjanssen 2 348 May-09-2024, 05:39 PM
Last Post: Pedroski55
  hi need help to make this code work correctly atulkul1985 5 981 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 821 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,073 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Code works but doesn't give the right results colin_dent 2 829 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Beginner: Code not work when longer list raiviscoding 2 951 May-19-2023, 11:19 AM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 2,062 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 1,619 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 1,015 Dec-29-2022, 08:59 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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