Python Python Sequences Sequence Operations Recap of Sequence Operations

ernestmurewa
ernestmurewa
857 Points

What will be printed when the following code is executed?

def check_lottery_number(num): lottery_numbers = [77, 24, 8, 18, 5, 64] if num in lottery_numbers: print(f'{num} is a winning number!') else: print(f'Try again, {num} is not a winning number.')

check_lottery_number(3)

1 Answer

ernestmurewa
ernestmurewa
857 Points

but there is no 3 there?

Daniel Turato
Daniel Turato
Java Web Development Techdegree Graduate 30,087 Points

There is, this is how I go to my answer:

  • Firstly, the method is called with 3 being passed into the method
  • As you go in the method body, the num passed in (3) is checked if it is inside lottery_numbers
  • As it's not inside the list, the else clause is executed hence "Try again, 3 is not a winning number" is printed.