0

The if statement with multiple conditions in one line below works properly:

exam1 = 70
exam2 = 60
exam3 = 50

if (100 >= exam1 and exam1 >= 60) or (100 >= exam2 and exam2 >= 60) or (100 >= exam3 and exam3 >= 60):
    print("You passed!!")

Output:

You passed!!

But, the if statement with multiple conditions in multiple lines below doesn't work properly:

exam1 = 70
exam2 = 60
exam3 = 50

if (100 >= exam1 and exam1 >= 60) or 
   (100 >= exam2 and exam2 >= 60) or 
   (100 >= exam3 and exam3 >= 60):
    print("You passed!!")

Then, I got the error below:

File "main.py", line 5
    if (100 >= exam1 and exam1 >= 60) or 
                                        ^
SyntaxError: invalid syntax

So, how can I write the if statement with multiple conditions and multiple lines?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129

1 Answers1

0

You can use backslashes for the if statement with multiple conditions in multiple lines as shown below:

exam1 = 70
exam2 = 60
exam3 = 50
                                   # ↓ Here
if (100 >= exam1 and exam1 >= 60) or \
   (100 >= exam2 and exam2 >= 60) or \
   (100 >= exam3 and exam3 >= 60): # ↑ Here
    print("You passed!!")

Then, it works properly as shown below:

You passed!!
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129