calculator

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???!!!!

You are viewing a single comment. View All
Answered by ReshiramWolfu (67) [earned 5 cycles]
ReshiramWolfu (67)

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

ReshiramWolfu (67)

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

James193 (8)

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

James193 (8)

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

ReshiramWolfu (67)

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

James193 (8)

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

ReshiramWolfu (67)

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

ReshiramWolfu (67)

@James193 i will try to figure it out

James193 (8)

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

ReshiramWolfu (67)

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

James193 (8)

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

James193 (8)

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

James193 (8)

@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"))
@James193 Just so you're aware, you don't need the `number = int()` lines in Python.