calculator

import time

addvariable = input("Give me a number")

addnumber = input("give me a second number")

print("your answer is...")

time.sleep(1)

print(addnumber + addvariable)

timesvariable = input("give me a number")

timesnumber = input("give me a second number")

print("your answer is...")

time.sleep(1)

print(timesvariable * timesnumber)

why cant i get my code to multiply or add???!!!!

NKY_28181503 (0)

input returns a string... i think

katyadee (1151)

Hey guys! Great work here. Remember that you can add your repls, and to always add context to your questions so other community members can learn from them too :-)

is this Python? If so, then you need to declare the variables.

timesvariable = int()

addvariable = int()

timesnumber = int()

addnumber = 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 thank you soc much :)!!!!

@James193 Very welcome!

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

addvariable = int()

timesnumber = int()

addnumber = 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"))

print("your answer is...")

time.sleep(1)

print(addnumber + addvariable)

else mat == 2:

timesvariable = int(input("give me a number"))

timesnumber = int(input("give me a second number"))

print("your answer is...")

time.sleep(1)

print(timesvariable * timesnumber)

@James193 here is the fixed version...

timesvariable = int()

addvariable = int()

timesnumber = int()

addnumber = 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"))

print("your answer is...")

time.sleep(1)

print(addnumber + addvariable)

elif mat == False:

timesvariable = int(input("give me a number"))

timesnumber = int(input("give me a second number"))

print("your answer is...")

time.sleep(1)

print(timesvariable * timesnumber)

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

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

@James193 i will try to figure it out

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

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

@ReshiramWolfu ok, thank you!

@ReshiramWolfu

ive done it!!!! all we needed to do was but " " around the True and False

here is the code

timesvariable = int()

addvariable = int()

timesnumber = int()

addnumber = 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"))

print("your answer is...")

time.sleep(1)

print(addnumber + addvariable)

elif mat == "False":

timesvariable = int(input("give me a number"))

timesnumber = int(input("give me a second number"))

print("your answer is...")

time.sleep(1)

print(timesvariable * timesnumber)

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

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

while True:

timesvariable = int()

addvariable = int()

timesnumber = int()

addnumber = 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"))

print("your answer is...")

time.sleep(1)

print(addnumber + addvariable)

elif mat == "2":

timesvariable = int(input("give me a number"))

timesnumber = int(input("give me a second number"))

print("your answer is...")

time.sleep(1)

print(timesnumber * timesvariable)

elif mat == "3":

divisionvariable = int(input("give me a number"))

divisionnumber = int(input("give me a second number"))

print("your answer is...")

time.sleep(1)

print(divisionvariable / divisionnumber)

elif mat == "4":

subvariable = int(input("give me a number"))

subnumber = int(input("give me a second number"))

print("your answer is...")

time.sleep(1)

print(subvariable - subnumber)

elif mat == "break":

break

@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 Just so you're aware, you don't need the

`number = int()`

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