Variables activity (Trinket)
Recommended mini-challenge: Turtle drawing challenge
This week your task will be to make a trivia game! The questions can be about whatever you want them to be.
New Python concepts:
Here is a simple example of how you can have Python 1) ask for user input, and 2) make a yes/no decision based on that input.
Recommended mini-challenge: If statement challenge or review worksheet
For loops let you repeat a block of code a specific number of times.
Here's the code for the snowflake branch.
Demo:
Recommended mini-challenge: For loop drawing challenge or baby shark challenge
Functions let you give a name to a chunk of code so you can call it up later in your program without writing all the instructions out again. There are a few functions you've already used in the first two sessions: range(), str(), int(), input().
Exercise 1: Go back to your snowflake from last week. What you want to make now is a function that draws a snowflake, so that all you need to type to make a new snowflake is this:
If you have time, you can make a fancy snowflake function where you can change the color, size, etc.:
Exercise 2: Starting from the trivia game you began working on in week 2, try to make a version of the game where the user input, answer comparisons, and scorekeeping all happen inside of a function. This will make adding new questions to your game much easier!
While loops act kind of like for loops, but you don't know how many times they're going to run. Instead, they keep running as long as some condition is true.
Exercise 3: Add a while loop in your trivia function to check if the user's answer is valid, and have them put in a new answer until it is.
This time, you get to choose your project! You have a few different options: