Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Sequences Sequence Operations Recap of Sequence Operations

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

but there is no 3 there?

Daniel Turato
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Daniel Turato
Java Web Development Techdegree Graduate 30,124 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.