#Dante D'Ambrogio #December 1, 23 #This program def multiply(num1, num2, num3=None,…
- User
#Dante D'Ambrogio #December 1, 23 #This program def multiply(num1, num2, num3=None, num4=None): result = num1 * num2 if num3 is not None: result *= num3 if num4 is not None: result *= num4 return result
def add(num1, num2, num3=None, num4=None): result = num1 + num2 if num3 is not None: result += num3 if num4 is not None: result += num4 return result
def subtract(num1, num2, num3=None, num4=None): result = num1 - num2 if num3 is not None: result -= num3 if num4 is not None: result -= num4 return result
def divide(num1, num2, num3=None, num4=None): if num2 == 0: return "Error: Division by zero is not allowed."
result = num1 / num2 if num3 is not None: if num3 == 0: return "Error: Division by zero is not allowed." result /= num3 if num4 is not None: if num4 == 0: return "Error: Division by zero is not allowed." result /= num4 return resultnum1=0 num2=0 num3=0 num4=0
print("How many numbers do you wish to use 2,3 or 4: ",end="") answer=int(input()) if answer == 2: print("What is the first number you wish to use: ",end="") num1=int(input()) print("What is the second number you wish to use: ",end="") num2=int(input()) elif answer == 3: print("What is the first number you wish to use: ") num1=int(input()) print("What is the second number you wish to use: ",end="") num2=int(input()) print("What is the third number you wish to use: ",end="") num3=int(input()) elif answer == 4: print("What is the first number you wish to use: ",end="") num1=int(input()) print("What is the second number you wish to use: ",end="") num2=int(input()) print("What is the third number you wish to use: ",end="") num3=int(input()) print("What is the fourth number you wish to use: ",end="") num4=int(input()) print("What fuction do you wish to do addition, subtraction, multiplication, or divison") opperation_answer=(input()) if opperation_answer == "addition": sum = add(num1, num2, num3, num4) result = num1 + num2 if num3 is not None: result += num3 if num4 is not None: result += num4 print(result) print(num1,"+", num2,"+", num3,"+", num4, "=",sum) elif opperation_answer == "subtraction": subtract(num1, num2, num3, num4) result = num1 - num2 if num3 is not None: result -= num3 if num4 is not None: result -= num4 print(result) print(num1,"-", num2,"-", num3,"-", num4, "=",result) elif opperation_answer == "multiplication": multiply(num1, num2, num3, num4) result = num1 * num2 if num3 is not None: result = num3 if num4 is not None: result = num4 print(num1,"", num2,"", num3_div,"*", num4_div, "=",result)
elif opperation_answer == "divison": divide(num1, num2, num3, num4) if num2 == 0: print ("Error: Division by zero is not allowed.") print("your second number is 0 re enter an number",end="") num2= int(input()) result = num1 / num2 if num3 is not None: if num3 == 0: print("Error: Division by zero is not allowed.") print("your third number is 0 re enter an number",end="") num3= int(input()) result /= num3 if num4 is not None: if num4 == 0: print ("Error: Division by zero is not allowed.") print("your fourth number is 0 re enter an number",end="") num4= int(input()) result /= num4 print(result) print(num1,"/", num2,"/", num3,"/", num4, "=",sum) why is it not printing the answers to the screen
- Assistant
It looks like you're missing print statements for displaying the final result in the "multiply" and "divide" sections of your code.
In the "multiply" section, you can add the following line before the last "print" statement:
print(num1,"*", num2,"*", num3,"*", num4, "=",result)In the "divide" section, you can add the following line before the last "print" statement:
print(num1,"/", num2,"/", num3,"/", num4, "=",result)This should ensure that the answers are printed to the screen correctly.
- User
- Assistant
- User
name all the inputs
- Assistant
Sure! Here are all the inputs mentioned in the pseudo code:
- num1 (the first number to be used)
- num2 (the second number to be used)
- num3 (the third number to be used)
- num4 (the fourth number to be used)
- answer (the number of numbers the user wants to use, should be either 2, 3, or 4)
- operation_answer (the operation the user wants to perform, should be one of: "addition", "subtraction", "multiplication", or "division")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.