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

Advertisements

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:
Ad

Advertisements

Joined
Mar 3, 2021
Messages
243
Reaction score
29
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

Top