← Back to Community
##### calculator
Profile icon
James193

import time
addvariable = input("Give me a number")
addnumber = input("give me a second number")
time.sleep(1)

timesvariable = input("give me a number")
timesnumber = input("give me a second number")
time.sleep(1)
print(timesvariable * timesnumber)
why cant i get my code to multiply or add???!!!!

Answered by ReshiramWolfu [earned 5 cycles]
Voters
Profile icon
Profile icon
ReshiramWolfu
Profile icon
James193
hotnewtop
Profile icon
ReshiramWolfu

is this Python? If so, then you need to declare the variables.
timesvariable = int()
timesnumber = int()
add them before the input, and then to fix the input, do
timesnumber = int(input("Enter a Number"))
Make sure to close both brackets

Profile icon
James193

@ReshiramWolfu thank you soc much :)!!!!

Profile icon
ReshiramWolfu

@James193 Very welcome!

Profile icon
James193

@ReshiramWolfu ive now tried to add some if statments for the user to choose if they want addition or multiplication but they dont work!!!

timesvariable = int()
timesnumber = int()
import time
mat = input("what would you like to do???, 1 = addition, 2 = multiplication")
if mat == 1:
addvariable = int(input("Give me a number"))
addnumber = int(input("give me a second number"))
time.sleep(1)
else mat == 2:
timesvariable = int(input("give me a number"))
timesnumber = int(input("give me a second number"))
time.sleep(1)
print(timesvariable * timesnumber)

Profile icon
ReshiramWolfu

@James193 here is the fixed version...
timesvariable = int()
timesnumber = int()
mat = bool()
import time
mat = input("what would you like to do???, True = addition, False = multiplication")
if mat == True:
addvariable = int(input("Give me a number"))
addnumber = int(input("give me a second number"))
time.sleep(1)
elif mat == False:
timesvariable = int(input("give me a number"))
timesnumber = int(input("give me a second number"))
time.sleep(1)
print(timesvariable * timesnumber)

Profile icon
James193

@ReshiramWolfu ive tried it but for some reason it dosent allow you to input the numbers???!!!

Profile icon
ReshiramWolfu

@James193 Have you indented the things in the if and elif blocks?

Profile icon
ReshiramWolfu

@James193 i will try to figure it out

Profile icon
James193

@ReshiramWolfu yes i have indented the things in the if and elif blocks,

Profile icon
ReshiramWolfu

@James193 I will sort it later. At School right now

Profile icon
James193

@ReshiramWolfu ok, thank you!

Profile icon
James193

@ReshiramWolfu
ive done it!!!! all we needed to do was but " " around the True and False
here is the code
timesvariable = int()
timesnumber = int()
mat = bool()
import time
mat = input("what would you like to do???, True = addition, False = multiplication")
if mat == "True":
addvariable = int(input("Give me a number"))
addnumber = int(input("give me a second number"))
time.sleep(1)
elif mat == "False":
timesvariable = int(input("give me a number"))
timesnumber = int(input("give me a second number"))
time.sleep(1)
print(timesvariable * timesnumber)

Profile icon
James193

@ReshiramWolfu thank you so much for all your efforts!!!

Profile icon
James193

@ReshiramWolfu here is the full version of my code now thanks to you!!!:)

while True:
timesvariable = int()
timesnumber = int()
divisionnumber = int()
divisionvariable = int()
subnumber = int()
subvariable = int()
mat = bool()
import time
mat = input("what would you like to do???, 1 = addition, 2 = multiplication, 3 = division or 4 = subtraction or break if you want to exit the calculator")
if mat == "1":
addvariable = int(input("Give me a number"))
addnumber = int(input("give me a second number"))
time.sleep(1)
elif mat == "2":
timesvariable = int(input("give me a number"))
timesnumber = int(input("give me a second number"))
time.sleep(1)
print(timesnumber * timesvariable)
elif mat == "3":
divisionvariable = int(input("give me a number"))
divisionnumber = int(input("give me a second number"))
time.sleep(1)
print(divisionvariable / divisionnumber)
elif mat == "4":
subvariable = int(input("give me a number"))
subnumber = int(input("give me a second number"))
time.sleep(1)
print(subvariable - subnumber)
elif mat == "break":
break

Profile icon
ReshiramWolfu

@James193 Well done! Your calculator is awesome! The next step up is to add powers of numbers and power roots of numbers. And to add floats instead of ints (Decimal instead of integer)

Profile icon
pyelias

@James193 Just so you're aware, you don't need the `number = int()` lines in Python.

Profile icon
ReshiramWolfu

@pyelias I learned that way, so i always declare the variables first. It is just the way i learned

Profile icon
NKY_28181503

input returns a string... i think

Profile icon