鶹Լ

Using OR

This Python (3.x) program also prints out a different message depending on the result of two tests. This time, though, if the score in either one of the tests is greater than or equal to 5, the message is output saying “You have passed!”. Otherwise, a message is output saying “Sorry, try again.”.

score1 = int(input("What did you score in test 1?"))
score2 = int(input("What did you score in test 2?"))
if score1 >= 5 or score2 >= 5:
	print("You have passed!")
else:
	print("Sorry, try again.")

This program uses selection to determine whether to print one message or the other:

  • The program examines the condition of the first Boolean expression score1 >= 5, in line 3.
  • If the score1 value is greater than or equal to 5, then the first condition is True.
  • The program then examines the condition of the second Boolean expression score2 >= 5, in line 3.
  • If the score2 value is greater than or equal to 5, then the second condition is True.
  • If either condition is True or both conditions are True, then the combined condition is True. As a result, the program prints “You have passed!”.
  • If neither is True, then the combined condition is False. As a result, the program prints “Sorry, try again.”.