user7196484 user7196484 - 13 days ago 5
Python Question

Beginner Python Functions Functions and Loops

My code is as follows:

import random

def CalcMulti(TT,TB):
ResultMutli = (TT * TB)
Answer1 = (input("What is the result of",TT,"*",TB,"?"))
if (ResultMulti == Answer1):
print("That is correct, the answer is",ResultMulti)
else:
print("That's not correct, sorry! The answer was",ResultMulti)

def CalcDivi(TT,TB):
ResultDivi = (TT / TB)
Answer2 = int(input("What is the result of ",TT,"/",TB,"?"))
if (ResultDivi == Answer2):
print("That is correct, the answer is",ResultDivi)
else:
print("That's not correct, sorry! The answer was",ResultDivi)

print("Thank you for using my program! Let's begin at the menu.")
print("")
ProgramLoop = 1
while (ProgramLoop == 1):
Num1 = random.randint(1,99)
Num2 = random.randint(1,99)
print("Your two numbers are",Num1,"and",Num2,". What should we do with these?")
print("")
print("1. Multiplication")
print("")
print("2. Division")
print("")
print("3. Exit Program")
print("")
MenuDecision = input("Enter M for Multiplication, D for Division, or E to Exit Menu!")
ExitLoop = 1
if (MenuDecision == "E") or (MenuDecision == "e"):
ProgramLoop = 0
print("Thank you for using my program! Bye!")
ExitLoop = 0
elif (MenuDecision == "D") or (MenuDecision == "d"):
CalcDivi(Num1,Num2)
elif (MenuDecision =="M") or (MenuDecision == "m"):
CalcMulti(Num1,Num2)
else:
print("Not a valid entry, sorry! Restarting...")
ExitLoop = 0
ProgramLoop = 1
while (ExitLoop == 1):
ProgramExit = input("Would you like to continue using the program? (yes/no)")
if (ProgramExit=="yes") or (ProgramExit=="YES") or (ProgramExit=="Yes"):
print("Back to the menu we go!")
ProgramLoop = 1
ExitLoop = 0
elif (ProgramExit=="no") or (ProgramExit=="NO") or (ProgramExit=="No"):
print("Thank you for using my program! Bye!")
ProgramLoop = 0
ExitLoop = 0
else:
print("Not a valid entry, yes or no please!")
ExitLoop = 1


Whenever I run the program and input "M" or "D" I get the following errors:

Traceback (most recent call last):
File "C:\Users\xxxxxx\Downloads\xxxxxxxxx Assignment 4.py", line 44, in <module>
CalcMulti(Num1,Num2)
File "C:\Users\xxxxxx\Downloads\xxxxxxxx Assignment 4.py", line 7, in CalcMulti
Answer1 = (input("What is the result of",TT,"*",TB,"?"))
TypeError: input expected at most 1 arguments, got 5

Answer

input() expects a single string as its input. Currently, you are passing it 5 strings. You should do something like the following:

def CalcMulti(TT,TB):
    ResultMutli = (TT * TB)
    string = "What is the result of {}*{}?".format(TT,TB)
    Answer1 = input(string)
    if (ResultMulti == Answer1):
        print("That is correct, the answer is",ResultMulti)
    else: 
        print("That's not correct, sorry! The answer was",ResultMulti)
Comments