Chapter 11: The Final Test!

      

   

   And here is the final test of this introduction to Python! 😱

   As with training, you will need to design two programs in 1h30.

   The first one is simple because it takes the code of luggage labeling, modifying it slightly. It will give you a score of 14/20, which is already not bad!... 😜

   The second one is longer. Here too, you will have to take the casino code and master the loops and conditions. If you are methodical, you will succeed! It will give you the coveted score of 20/20! 😇

   Come on, let's go! Top time! 🕑

        

Program 1: Punishment Maker

You will code a software that will ask the user to enter a punishment phrase to copy.

 You will then ask him how many times he has to copy it.

 The computer will then copy this sentence as many times as indicated with a for loop, indicating for each the line number.

Example of result for 4 punishment sentences to copy (Reminder: the user can put whatever sentence he wants, don't hardcode it!):

#00 – I must not cheat using ChatGPT!
#01 – I must not cheat using ChatGPT!
#02 – I must not cheat using ChatGPT!
#03 – I must not cheat using ChatGPT!

   

      Already finished? Well, let's move on to the second program then! 🤪

      

Program 2: Game: Guess the number I'm thinking of!

You are going to program your first video game! The computer will draw a random number (like in the casino) and then you will have to guess it. It will tell you if you are above or below and if you are heating up.

Advices:

Your game will consist of two nested while loops: the first is the game loop and asks you if you want to play, the second is the one that makes you guess the number and only stops if you find it, sending you back to the first loop.

1st while loop : you will ask the player if he wants to play. If he accepts you will launch the game, otherwise you will quit.

You will then initialize the number of trials to 0.

You will have the computer randomly draw a number between 1 and 99 using the following code (the same as for the casino):

#To be placed at the very beginning of the file
import random 

#Write your code here

# Allows you to draw a random number between 1 and 99 
# and store it in the variable nb 
nb = random.randint(1, 99)

 

In a 2nd while loop, you will ask the user to guess this number and you will guide him by doing tests (if / elif) to know if his number is bigger / smaller and if he heats up or not (to + 5 or - 5). Do not hesitate to nest if statements inside each other and to use elif / else!

When the user finds the right number, you will congratulate him and indicate the number of tries it took him to find it.

You will then return to the beginning of the program (1st while loop) by exiting the second loop.

Good luck! 😇

      

   PS: This being a real assessment that I give to my students, the correction is not available on the site. Contact me, if you really need it! 😉    

      

     And that concludes this introduction to programming using Python! 😀

   A sequel may come later, for more advanced levels. In the meantime, you can go to the Pygame tutorial to discover how to program the basics of a video game! 😍

   See you soon and may the Python Programmaforce be with you! ☺️

   

This site uses cookies to enable you to log in. We do not store or sell any personal data. By continuing to use this website, you agree to their use. Thanks!