DescriptionImplement your first loopy application.
TypeHand-in assignment with oral explanation.
DurationAbout 1 working day.
Progress points1.5
Learning goals
  • Branch using if, elif and else. 33%
  • Use loops. 33%
  • Use comments and whitespace to improve readability. 33%

Learning materials

Assignment

Today we are opening our Christmas tree shop. And we are selling some very strange trees. Let's build an application to showcase our three types of trees, of various heights. We'll be creating the application step-by-step, but here is how the final product should work:

Tiny trees

Objective #13.0 points

Create the basics for the Christmas tree shop application shown above. For now, it won't have to ask for tree height, and it won't have to properly handle invalid user input.

It should be able to produce output like this:

*** Welcome to Santa's Woodshop ***

Let's draw a tree!
What shape should it have? [right/left/normal] right
*
**
***
Would you like to see another tree? [yes/no] yes

Let's draw a tree!
What shape should it have? [right/left/normal] left
  *
 **
***
Would you like to see another tree? [yes/no] yes

Let's draw a tree!
What shape should it have? [right/left/normal] normal
  *
 ***
*****
Would you like to see another tree? [yes/no] no

Hint: You can create an 'infinite loop' by wrapping the repeatable part of your program in a while True. Use break to break out of a loop (making it not so infinite after all).

Trees of all sizes

Objective #23.0 points

Modify your program to ask for the tree height before your ask for the tree shape, and print trees of dynamic heights.

Your application should now be able to produce output like this:

*** Welcome to Santa's Woodshop ***

Let's draw a tree!
How tall would you like it to be? 5
What shape should it have? [right/left/normal] right
*
**
***
****
*****
Would you like to see another tree? [yes/no] yes

Let's draw a tree!
How tall would you like it to be? 3
What shape should it have? [right/left/normal] left
  *
 **
***
Would you like to see another tree? [yes/no] yes

Let's draw a tree!
How tall would you like it to be? 10
What shape should it have? [right/left/normal] normal
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
Would you like to see another tree? [yes/no] no

Hint: You'll need to add loops to go over each line of the trees. To repeat a string a certain number of times, you can multiply it by an integer. So 'test' * 3 would become 'testtesttest'.

Error handling

Objective #33.0 points

Finish your application, so that it works exactly like the video on the top of the assignment.

  • When it inputs an invalid tree height, it should ask again.
  • When it inputs an invalid tree shape, it should go back to Let's draw a tree!.
  • When it inputs an invalid yes/no choice, it should ask again.

Hint: You'll need to add some loops, and you'll want to make use of break and continue.

Objective #4: PunctualityMUST

Make sure that the output of your program:

  • Closely matches the provided video and example outputs.
  • Contains no spelling errors. Hint: Install the Code Spell Checker extension (by streetsidesoftware) for Visual Studio Code. Just take a minute to do this. Really.
  • Uses correct and easy to understand messages.
  • Uses capital letters, white spaces and punctuation in all the right places.

Code quality

Objective #5+ 1.1 points- 3.3 points

Your code should be easy to understand, using sensible variable names, empty lines to separate distinct parts of the program and consistent use of whitespace.

Rubrics mapping and grading

#1#2#3#5-Σ
Branch using if, elif and else.1.001.001.001.50-1.123.3
Use loops.1.001.001.001.50-1.123.3
Use comments and whitespace to improve readability.1.001.001.001.50-1.123.3
Base grade.1.001.0
Σ3.003.003.004.50-2.3711.1

Learning materials

Assignment

Since we need some more practice with loops, we're going to play a little game with our own cornflakes (inspired by a mix of froot loops and alphabet soup). Perfect to play while having breakfast!

Game setup

Objective #11.5 points

Create the basics for the alphabet loops game. All inputs need to be handled cleanly (hufterproof) You will need to create a top-level game loop and ask a user for their name and then for a guess. The guess needs to be a single letter character and nothing else. You should prompt the user to give a valid input as long as the user has not given you a valid input.

It should be able to produce output like this:

*** Welcome to Alphabet Loops ***

Please enter your name: Luuk
Guess a letter!:

Countdown

Objective #21.5 points

To start our little game, we will want a countdown. This countdown simple counts down from 10 and prints the amount of seconds before the game starts.

((hint you'll want to use the time.sleep() function from the time package. You can add this by adding 'import time' to the top of your program)

It should be able to produce output like this:

*** Welcome to Alphabet Loops ***

Please enter your name: Luuk
Countdown: 10
Countdown: 9
Countdown: 8
Countdown: 7
Countdown: 6
Countdown: 5
Countdown: 4
Countdown: 3
Countdown: 2
Countdown: 1

Are there winners?

Objective #31.5 points

Now you need to randomly set a letter as being the secret letter. This letter can be any of our known 26-letter counting alphabet. Make sure that the letter is always lower case, as otherwise it would make the game almost impossible but definitely not fun. If you have a valid input (and break out of the valid input loop), check the input against the chosen word. If you have a match, display a congratulations message. If you don't have a match, say 'Sorry try again!'.

Your application should now be able to produce output like this:

*** Welcome to Alphabet loops ***
Please enter your name: Luuk
Guess a letter!: a
Sorry, try again
Guess a letter!: blabla
please enter a valid letter!
Guess a letter!: z
You won congratulations!

Hint: to randomly select a random letter from the alphabet you might want to use the 'import random' and 'import string'. As there are functions to retrieve all letters from the alphabet, and a function to randomly select one of those options.

Countdown

Objective #41.5 points

Now we didn't add the countdown for nothing, we want to keep track of how long a user is busy trying to guess the number up until the point a winning guess is confirmed. You could do this by using the time module as you did before for the countdown but now using it to keep track of time and calculating the result.

Small reminder that we don't care about millie seconds and want our our result to be in real, round, seconds

*** Welcome to Alphabet Loops ***

Please enter your name: Luuk
Countdown: 10
Countdown: 9
Countdown: 8
Countdown: 7
Countdown: 6
Countdown: 5
Countdown: 4
Countdown: 3
Countdown: 2
Countdown: 1
Guess a letter!: w
Luuk! You won in 1 attempts after 25 seconds, congratulations!

Keep going!

Objective #51.5 points

At last we want to add one last loop. This loop will ask the user if they want to keep playing our game. If they do (by selecting 'y'), we need to generate a new random letter. If they don't (option 'n') we want to exit the application. If we have an invalid input we want to keep asking the user enter a valid 'y' or 'n'.

You won in 8 attempts, congratulations!
Would you like to play another game? (y/n): bla
That's not a valid input! Please select 'y' or 'n'
Would you like to play another game? (y/n): y
Guess a letter!: a

Error handling

Objective #61.5 points

Finish your application, so that it works exactly like the video on the top of the assignment.

  • When it inputs an invalid alphabetic character
  • When it inputs an invalid option for the y or n question to continue the game

Hint: You'll need to add some loops

Objective #7: PunctualityMUST

Make sure that the output of your program:

  • Closely matches the provided video and example outputs.
  • Contains no spelling errors. Hint: Install the Code Spell Checker extension (by streetsidesoftware) for Visual Studio Code. Just take a minute to do this. Really.
  • Uses correct and easy to understand messages.
  • Uses capital letters, white spaces and punctuation in all the right places.

Code quality

Objective #8+ 0.5 points- 1.6 points

Your code should be easy to understand, using sensible variable names, empty lines to separate distinct parts of the program and consistent use of whitespace.

Rubrics mapping and grading

#1#2#3#4#5#6#8-Σ
Branch using if, elif and else.0.500.500.500.500.500.500.75-0.563.1
Use loops.0.500.500.500.500.500.500.75-0.563.1
Use comments and whitespace to improve readability.0.500.500.500.500.500.500.75-0.563.1
Base grade.1.001.0
Σ1.501.501.501.501.501.502.25-0.6810.5