Book a free demo

๐Ÿ Python from scratch ยท Session 1

Hello, Python: print, text and comments: practice sheet

Name ____________________Date __________Score ____ / 28

โ† Back to the lesson

Part 1: What is a program?

Remember: A program is a list of instructions for a computer. Python reads it from the top line to the bottom line, one line at a time.

  1. 1. Warm-up Print exactly: Hello, world!

  2. 2. Warm-up Print three lines: your name, your class and your school.

  3. 3. Core Print this poem exactly, on two lines:
    Roses are red
    Python is fun

  4. 4. Stretch ๐Ÿ”ฅ Print a triangle of stars exactly like this, one print per line:
    *
    **
    ***
    ****

Part 2: Text and numbers

Remember: Text inside quotes is a string. Numbers need no quotes, and Python can do maths with them: + adds, - subtracts, * multiplies, / divides.

  1. 5. Warm-up Make Python work out 25 + 17 and print the answer.

  2. 6. Core Print the sum as text on line 1 and its answer on line 2:
    7 + 5
    12

  3. 7. Core Print exactly: Hours in a week: 168, with Python doing the multiplying.

  4. 8. Stretch ๐Ÿ”ฅ A cinema has 18 rows of 24 seats. Print two lines, worked out by Python:
    Seats: 432
    Two shows: 864

  5. 9. Stretch ๐Ÿ”ฅ Asha scored 85, 90 and 77 in three tests. Print her average, worked out by Python (it should show 84.0).

Part 3: Comments, joining and repeating text

Remember: A line starting with # is a comment. Python skips it; it is a note for people.

  1. 10. Warm-up Print a line of exactly 15 # signs using * (do not type 15 of them).

  2. 11. Core Print this box exactly, using * for the dashes:
    +----------+
    | PYTHON |
    +----------+

  3. 12. Core Print a staircase of five lines: #, ##, ###, ####, ##### (use * on every line).

  4. 13. Stretch ๐Ÿ”ฅ Write a program with at least two comment lines that prints a flag:
    *****=====
    *****=====
    *****=====
    Use * to build each line from "*" and "=".

Part 4: Reading an error and fixing it

Remember: When Python cannot understand a line it stops and shows an error with a line number.

  1. 14. Warm-up Fix the program so it prints: Good morning

    print("Good morning)
  2. 15. Core Fix both lines so the program prints Hello and then World.

    Print("Hello")
    print("World"
  3. 16. Stretch ๐Ÿ”ฅ There are three mistakes. Fix them so the output is exactly:
    Score: 10
    Total: 15
    Bye

    print("Score:" 10)
    print("Total:", 5 + )
    print(Bye)

Activity 1: Name badge

  1. 17. Build a name badge one step at a time. Press Check after each step to see which parts already work.

    1. Print a top border of exactly 30 = signs, using *.
    2. Print NAME: followed by your name on one line.
    3. Print your age, then on the next line your age in months worked out by Python (age ร— 12).
    4. Print one hobby you love.
    5. Print the bottom border, the same as the top.
    # Step 1: top border of 30 = signs
    
    # Step 2: NAME: and your name
    
    # Step 3: your age, then your age in months (let Python multiply)
    
    # Step 4: a hobby
    
    # Step 5: bottom border
    

Activity 2: Shop receipt

  1. 18. Print a receipt that looks exactly like the one below. The total must be worked out by Python.
    ------------------------
    SUPER STATIONERY
    ------------------------
    Pencil 12
    Notebook 45
    Eraser 8
    Total 65
    Thank you!

    1. Print a line of 24 dashes using *.
    2. Print the shop name, then another line of 24 dashes.
    3. Print each item and its price on its own line (use a comma between them).
    4. Print Total and the sum 12 + 45 + 8, worked out by Python.
    5. Print Thank you! at the end.
    # Step 1 and 2: the header
    
    # Step 3: the three items
    
    # Step 4: the total (let Python add)
    
    # Step 5: thank you
    

Activity 3: Times-table strip

  1. 19. Print the first six lines of the 7 times table, with Python doing every multiplication:
    7 x 1 = 7
    7 x 2 = 14
    โ€ฆ up to 7 x 6 = 42. Then print a line of 20 stars and the line: Total of the answers: 147 (worked out by Python).

    1. Print 7 x 1 = and the answer 7 * 1, using a comma.
    2. Do the same for 2 to 6.
    3. Print a line of 20 stars.
    4. Print Total of the answers: and let Python add 7 + 14 + โ€ฆ + 42 (or 7 * 21).
    # Step 1
    print("7 x 1 =", 7 * 1)
    # Step 2: lines for 2 to 6
    
    # Step 3: 20 stars
    
    # Step 4: the total
    

Predict the output

Work it out on paper first, then type it into the lesson page to check.

  1. 20. What does this print?

    print("5 + 3")
  2. 21. What does this print?

    print(5 + 3)
  3. 22. What does this print?

    print("Hi", "there")
  4. 23. What does this print?

    print("ab" + "c" * 3)
  5. 24. What does this print?

    print(2 * 3 + 1)
  6. 25. What does this print?

    print("-" * 3 + ">")

Homework

  1. 26. Warm-up Print a three-line address label: your name, your city and your country.

  2. 27. Core Print the number of seconds in one day, worked out by Python, with the label Seconds in a day:

  3. 28. Stretch ๐Ÿ”ฅ Print a hollow square 5 wide, using * and +:
    *****
    * *
    * *
    *****

Answer key

  1. print("Hello, world!")
  2. print("Asha")
    print("Class 5")
    print("Green Valley School")
  3. print("Roses are red")
    print("Python is fun")
  4. print("*")
    print("**")
    print("***")
    print("****")
  5. print(25 + 17)
  6. print("7 + 5")
    print(7 + 5)
  7. print("Hours in a week:", 24 * 7)
  8. print("Seats:", 18 * 24)
    print("Two shows:", 18 * 24 * 2)
  9. print((85 + 90 + 77) / 3)
  10. print("#" * 15)
  11. print("+" + "-" * 10 + "+")
    print("|  PYTHON  |")
    print("+" + "-" * 10 + "+")
  12. print("#" * 1)
    print("#" * 2)
    print("#" * 3)
    print("#" * 4)
    print("#" * 5)
  13. # my flag
    # three equal stripes
    print("*" * 5 + "=" * 5)
    print("*" * 5 + "=" * 5)
    print("*" * 5 + "=" * 5)
  14. print("Good morning")
  15. print("Hello")
    print("World")
  16. print("Score:", 10)
    print("Total:", 5 + 10)
    print("Bye")
  17. # Step 1
    print("=" * 30)
    # Step 2
    print("NAME: Kabir")
    # Step 3
    print("Age:", 11)
    print("Age in months:", 11 * 12)
    # Step 4
    print("I love: football")
    # Step 5
    print("=" * 30)
  18. print("-" * 24)
    print("SUPER STATIONERY")
    print("-" * 24)
    print("Pencil", 12)
    print("Notebook", 45)
    print("Eraser", 8)
    print("Total", 12 + 45 + 8)
    print("Thank you!")
  19. print("7 x 1 =", 7 * 1)
    print("7 x 2 =", 7 * 2)
    print("7 x 3 =", 7 * 3)
    print("7 x 4 =", 7 * 4)
    print("7 x 5 =", 7 * 5)
    print("7 x 6 =", 7 * 6)
    print("*" * 20)
    print("Total of the answers:", 7 + 14 + 21 + 28 + 35 + 42)
  20. 5 + 3
  21. 8
  22. Hi there
  23. abccc
  24. 7
  25. --->
  26. print("Kabir")
    print("Pune")
    print("India")
  27. print("Seconds in a day:", 24 * 60 * 60)
  28. print("*" * 5)
    print("*" + " " * 3 + "*")
    print("*" + " " * 3 + "*")
    print("*" * 5)
Chat on WhatsApp
Esc

Try