8️⃣

6.8 Practice

Practice

Sum List

Create a program that prints the sum of numbers in a list. A test list has been given to you.

Integer Info

Create a program that takes an integer as input and creates a list with the following elements:
  • The number of digits
  • The last digit
  • A True boolean value if the number is even, False if it is odd.
Print the list. Some examples are given to help check your work

Too Long

Print and remove all elements with a length greater than 4 in a given list of strings.

Snookle Game

Snookle the sheep wants to play a game. Given a list of positive integers and a main number, the player iterates through each element in the list and chooses to either add it or to subtract it from the current main number.
 
This is done by having the user enter either "add" or "subtract" every turn. The main number will be updated to the new value.
 
A player wins if they make 12 to be the main number. If the end of the list is reached, go back to the first element in the list and keep going until the player wins.
 
Code the game for Snookle!
A demo can be seen here and below
Video preview

Grocery List

Create a program that prompts the user to continuously enter items for a grocery list. Stop asking them for items when the user enters "quit".
Print the grocery list in a numbered format.
Ask the user to enter prices for each item in the grocery list in order.
Finally, ask the user how many of each item they bought. Based on their input, calculate the total grocery bill and display it. (Bonus points if you can format the money so that it displays 2 decimals)
 
You can view the demo here or below
Video preview

Monty Hall

Code the classic Monty Hall problem!
The following is a description of the Monty Hall Problem:
There are three close doors. 2 have goats behind them. Only one has a car behind it. you don't know which door has what. The goal is to pick the door that has the car behind it.
After you make a choice, Monty (the host) opens a door that you did not choose, revealing a goat.
You are then asked whether you want to change your choice to the other door. The door you choose is more likely to have a car if you switch to the other door, apparently!
 
More step-by-step instructions (pseudocode) are commented on in the practice template.
 
You can read more about the Monty Hall Problem here
You can view a demo here or below
Video preview

Next Section

 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.