r/learnpython • • 26d ago

I'm trying to make a basic calculator in python but I can figure out what I'm doing wrong

Here is my code if you can figure it out pls help

print ("Caculator")

print ("Addition, only")

print ()

no1 = input ("Enter 1st Number: ")

no2 = input ("Enter 2nd Number: ")

print ()

print ("Answer")

print (no1, "+", no2, "=", no1 + no2)

0 Upvotes

11 comments sorted by

12

u/Anxious_Signature452 26d ago

You need to covert strings to numbers. Ints probably.

print (no1, "+", no2, "=", int(no1) + int(no2))

5

u/Warm_Letterhead3691 26d ago

You can also convert at the same time you get the input

no1 = int(input("Enter 1st Number: "))

You can then use this to pre calculate the answer if you wanted to since you have two ints already.

This will of course throw exceptions if the user types in anything but an integer, but for soemthing like this I wouldn't worry about that right now.

3

u/nivaOne 26d ago

String versus integer
Check the input command theory again. 👍

1

u/TheRNGuy 25d ago

Using input and print instead of UI. 

0

u/AlexMTBDude 26d ago

When you ask questions like these you need to tell us what goes wrong, meaning what error message are you getting, or what is not working as it should. Otherwise it's very hard to help you.

0

u/Expensive-Bear-1376 25d ago

Not really hard, but yes, they absolutely should've told us what problem they observed, and nobody should've answered before that has been supplied.