For Loop Part 1 - Easy
For Loop Part 1 - Easy
Iteration
Lesson objectives…
Understand the structure of a for loop.
Solve real-world problems using for loops.
Understand how to use selection and
iteration on a single program to solve a
problem.
Created by Mr Suffar
Iteration theory: https://youtu.be/myTwo-B9E4k
Created by Mr Suffar
Knowledge phase
Created by Mr Suffar
Structure of a for loop
Variable Number of iteration End with a colon
for __ in range(__) :
code to be run here
more code to be run here
this code not in the for loop
Created by Mr Suffar
Number of iteration
Variable
Created by Mr Suffar
Number of iteration
Variable
Created by Mr Suffar
Start from
Variable
Up to but not included
Created by Mr Suffar
Start from
Variable
Up to but not included
Created by Mr Suffar
number = int(input("Enter number"))
for i in range (number) :
print("hello")
Created by Mr Suffar
72. https://youtu.be/m4feUCbSbIU
• Copy the code below and run it.
• Then change the % to a "$".
• Run it again then comment on the code to explain the purpose of the code.
Created by Mr Suffar
73. Use a for loop to display “welcome” 100 times. Then display “bye” ONCE.
Paste your code below:
https://youtu.be/ptQlhaUF8g8
Created by Mr Suffar
74. Create a program that counts from 1 to 100.
Paste your code below:
https://youtu.be/CJxCX91EguY
Created by Mr Suffar
75. Ask the user for a number. Display the times table of that number from 1 to 100.
Paste your code below:
https://youtu.be/h34JCAGAujU
Created by Mr Suffar
76. Ask the user for a number. Repeat ‘I like turtles’ a certain number of times, based on a
number entered by the user. (If the user enters 5, display I like turtles 5 times)
Paste your code below:
https://youtu.be/S8vzq2pTXLM
Created by Mr Suffar
77. Ask the user to enter a name. Ask the user how many times they want their name to be
displayed. Display the user’s name repeatedly depending on the user’s answer.
Paste your code below:
https://youtu.be/2liNPIqBOcA
Created by Mr Suffar
78. Ask the user for a number. Display the times table of that number from 1 to 5 in the
following style
Paste your code below:
https://youtu.be/5Tu8qHI-iB8
Created by Mr Suffar
79) Ask the user their name and their age. Print their name the number of times as their
age.
Paste your code below:
https://youtu.be/6jMDtCSWf5c
Created by Mr Suffar
80) Write a program that:
• Asks the user to enter a number
• Adds 5 to that number
• Displays the new number on the screen.
• Make the above process repeat 6 times.
Paste your code below:
https://youtu.be/sDr1Wo1ndEI
Created by Mr Suffar
81. Create a program that:
• Asks the user for a name.
• Display the user’s name as many times as the letters in the name. For example: If the
name has 7 letters, display that name 7 times.
Paste your code below:
https://youtu.be/CDFqJHuWEjE
Created by Mr Suffar
82) Create a program that:
• Asks “how many negatives did you get?”
• If the answer is 1, display prompt 10 times.
• if the answer is 2, display reminder 50 times.
• If the answer is 3, display warning 100 times
• Display removal 500 times if any other number is entered.
Paste your code below:
https://youtu.be/_3DIOrsf77A
Created by Mr Suffar
83) Wzzap market is a shop that sells face masks.
Create a program that:
• Asks if the shop is open.
• If the user answers "yes", display "Can I get a face mask please" 5 times using a for
loop.
• Otherwise display “I need to stay at home!” 100 times using a for loop.
Paste your code below:
https://youtu.be/Zoh_TZNxbXQ
Created by Mr Suffar
84) Create a program that:
• Asks for the user’s age.
• If the age is greater than 12, display happy birthday 100 times.
• Otherwise display happy birthday 12 times.
Paste your code below:
https://youtu.be/qMDj9pqkEck
Created by Mr Suffar
85) Create a program that:
• Displays all odd numbers between 1 and 99.
Paste your code below:
https://youtu.be/l4gS8fdv1Ho
Created by Mr Suffar
86) Create a program that:
• Displays all even numbers between 1 and 100.
Paste your code below:
https://youtu.be/yVAmfSIrges
Created by Mr Suffar
Homework: https://youtu.be/LDjUhj7yvkQ
Created by Mr Suffar