Hack Forums
[Python] Tried making a calculator and I can't figure out what I did wrong.. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Tried making a calculator and I can't figure out what I did wrong.. (/showthread.php?tid=5629778)



Tried making a calculator and I can't figure out what I did wrong.. - Jake - May 23, 2017

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



* - szuszi2 - May 23, 2017

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 :)


* - Jake - May 23, 2017

(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.


* - szuszi2 - May 23, 2017

you are welcome my friend :D have fun coding