(Python Foundation) % Remaining Operator Error Problem

Asked 2 years ago, Updated 2 years ago, 58 views

%d %d in the last line gives an error because of the % in the middle. It's one of the arithmetic operators, and it seems to have an error because you couldn't read it as an arithmetic operator and then called % (real variable). How can I stay in this format but work it out?

num1 = int("Enter the first digit":")) num2 = int("Enter the second digit":"))

print("%d + %d = %d" % (num1,num2,num1+num2)) print("%d - %d = %d" % (num1,num2,num1-num2)) print("%d * %d = %d" % (num1,num2,num1*num2)) print("%d / %d = %d" % (num1,num2,num1/num2)) print("%d % %d = %d" % (num1,num2,num1 %num2))

python modular-operator

2022-09-21 20:21

1 Answers

%%

num1 = int(input="Enter the first number":")) 
num2 = int("Enter the second digit":"))

print("%d + %d = %d" % (num1,num2,num1+num2)) 
print("%d - %d = %d" % (num1,num2,num1-num2)) 
print("%d * %d = %d" % (num1,num2,num1*num2)) 
print("%d / %d = %d" % (num1,num2,num1/num2)) 
print("%d %% %d = %d" % (num1,num2,num1 %num2))


2022-09-21 20:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.