Chapter 9: Let's create our first programs together

      

    

   To practice a little more before the final test and to re-appropriate everything we have seen so far, we will create two fairly basic programs. The first will be very easy but the second a little bit harder. 👺

   Here we go! 😃

        

Program 1: Baggage labeling

You will program an automatic baggage tagging software for the new Meruvia Airport.

The program will ask the user to enter the number of bags to tag as an integer (int).
It will then ask for the contents of the tag to print as a string (str).
The program will then print all the tags by copying its contents, followed by the checked baggage number. You will use a for loop to do this.

Example result for 4 bags:

MERUVIA – Checked Baggage No. 00
MERUVIA – Checked Baggage No. 01
MERUVIA – Checked Baggage No. 02
MERUVIA – Checked Baggage No. 03

   

   

Program 2: AI Dealer

Meruvia's new Casino Royale asks you to design a program that rolls dice randomly, without cheating of course! 🙃

You will use the following code to generate a random number:

#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)

You will ask the user to enter an integer (int) which will be the maximum value of your dice roll (you will therefore have to change this 99 for a variable...).

You will roll the dice with the above function and display the value.

Finally, you will put this program in a while loop asking on each turn if the user wants to continue rolling the dice. Otherwise you will exit the program. 

Good luck! 😇

   

      

   There you go, I'll let you think about it a bit and we'll see you in the next chapter for the correction! 😀

        See you soon for the rest! ☺️

   

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!