-3

So, I have 3 variables the total of which should be 120. I have done the verification of that. The variables should be equal to 0 or 20 or 40 or 60 or 80 or 100 or 120. I have done the verification for that as well but now what I need is for my program to check if variable 1 is 100 and variable 2 is 0 or 20 and variable 3 is 0 or 20 in terms to output a message. Then I need to check if variable 1 is 40 or 60 or 80 variable 2 is 0 or 20 or 40 or 60 or 80 and variable 3 is 0 or 20 or 40 or 60 in terms to output a different message.

if pass_credit + defer_credit + fail_credit != 120:
    print("Total incorrect!")
elif pass_credit == 120 and defer_credit == 0 fail_credit == 0:
    print("Progress")
    break
elif pass_credit == 100 and defer_credit == 0 or 20 and fail_credit == 0 or 20:
    print("Progress - module trailer")
    break

That's what I have so far

Thanks in advance

Softy
  • 5
  • 3

2 Answers2

0

If you want to use a general message for all the good combinations (with the values), use:

a, b, c = 80, 40, 0
message = "The values are: "
for i, var in enumerate([a, b, c]):
    message += "Variable " + str(i + 1) + " is: " + str(var) + ", "
print(message[:-2] if a + b + c == 120 else "Total incorrect!")

Output:

The values are: Variable 1 is: 80, Variable 2 is: 40, Variable 3 is: 0

If you want a different message for every possible combination, continue your elifs to cover all options (with @gelonida's correction for the syntex). No smart way to do that.

Aryerez
  • 3,417
  • 2
  • 9
  • 17
0

the semantics of this line is wrong:

elif pass_credit == 100 and defer_credit == 0 or 20 and fail_credit == 0 or 20:

Either write

elif pass_credit == 100 and (defer_credit == 0 or defer_credit == 20) and (fail_credit == 0 or fail_credit == 20):

or write

elif pass_credit == 100 and defer_credit in (0, 20) and fail_credit in (0, 20):
gelonida
  • 5,327
  • 2
  • 23
  • 41