Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Tried making a calculator and I can't figure out what I did wrong..

I was loooking over some Beginner python stuff A LOT recently cause i'm interested and it seems like a lot of people's first project is something simple like a calculator. Except i'm struggling and IDK what I even did.. I've looked over other calculators online and it looks like i've done nothing wrong? It always skips to the else and doesn't even consider the elif's I don't think. or I did the functions wrong or something. Pls help.

Code:
Code
print ("Welcome to Disinterested's first calculator.")
#first define the functions

#addition
def addition(x, y):
    return x + y

#subtraction
def subtraction(x, y):
    return x - y

#multiplication
def multiplication(x, y):
    return x * y

#division
def division(x, y):
    return x / y

print ("What would you like to use?")
print ("1. Addition")
print ("2. Subtraction")
print ("3. Multiplication")
print ("4. Division")

decision = int(input("Enter your decision (1/2/3/4): "))

number1 = int(input("Enter first number: "))
number2 = int(input("Enter second number: "))

if decision == '1':
    print (number1," + ",number2," = ", addition(number1, number2))
    
elif decision == '2':
    print (number1," - ",number2," = ", subtraction(number1, number2))
    
elif decision == '3':
    print (number1," * ",number2," = ", multiplication(number1, number2))
    
elif decision == '4':
    print (number1," / ",number2," = ", division(number1, number2))

else:
    print ("WTF ARE YOU DOING WRONG")

Output:
Code
Welcome to Disinterested's first calculator.
What would you like to use?
1. Addition
2. Subtraction
3. Multiplication
4. Division
Enter your decision (1/2/3/4): 4
Enter first number: 1
Enter second number: 1
WTF ARE YOU DOING WRONG
you are casting the decisions to an int and your checking for a char :D just change the ifs right hand sides to 1,2,3,4 instead of '1','2'.... etc :)
(May 23, 2017 08:00 AM)szuszi2 Wrote:  you are casting the decisions to an int and your checking for a char :D just change the ifs right hand sides to 1,2,3,4 instead of '1','2'.... etc :)
YOU'RE MY SAVIOR! Thank you so much.
you are welcome my friend :D have fun coding


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by theN20Dec 3, 2020 02:31 PM 9 322 Dec 3, 2020 02:31 PM
Last Post: tsuki
[Python] by OliFlawAug 23, 2017 03:13 AM 7 158 Aug 23, 2017 03:13 AM
Last Post: OliFlaw
[C] by Smack TricksDec 3, 2014 01:07 PM 9 188 Dec 3, 2014 01:07 PM
Last Post: Smack Tricks