Another student in my class showed us this code

Joined
Mar 8, 2022
Messages
2
Reaction score
0
and everyone else started to mess around with it and they got it to run but I cant figure out why it wont print anything. this is my first semester and I'm new to this.


def main():

numOne = int(input("What is your first number"))
numTwo = int(input("input your second number"))
operation = input("input your operator")

def performOperation(numOne, numTwo, operation):

if(operation == "+"):
result1 = int(numOne) + int(numTwo)
print(result1)
elif(operation == "-"):
result2 = int(numOne) - int(numTwo)
print(result2)
elif(operation == "*"):
result3 = int(numOne) * int(numTwo)
print(result3)
elif(operation == "/"):
result4 = int(numOne) / int(numTwo)
print(result4)
else:
print("YOU DID NOT PRINT A VALID OPERATION SYMBOL")

main()
 
Joined
Mar 8, 2022
Messages
2
Reaction score
0
i know the three variables uptop are unused thats what my IDE is telling me but ive tried making them global or using return and idk.... it runs though it asks me all the right questions just wont output the final answer ok im still fiddling with it
heres this :


def main():

numOne = int(input("What is your first number"))
numTwo = int(input("input your second number"))
operation = input("input your operator")

def performOperation(numOne, numTwo, operation):

if(operation == "+"):
print(int(numOne) + int(numTwo))
elif(operation == "-"):
print(int(numOne) - int(numTwo))
elif(operation == "*"):
print(int(numOne) * int(numTwo))
elif(operation == "/"):
print(int(numOne) / int(numTwo))

else:
print("YOU DID NOT PRINT A VALID OPERATION SYMBOL")

main()
 
Last edited:
Joined
Mar 3, 2021
Messages
240
Reaction score
30
You're not calling the function after you get the user's input. After "operation =", call performOperation(numOne, numTwo, operation).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top