0% found this document useful (0 votes)
4 views28 pages

For Loop Part 1 - Easy

The document outlines lessons on string manipulation and iteration in programming, specifically focusing on the use of for loops. It includes examples and tasks for students to practice their understanding of loops, string functions, and user input. Additionally, it provides links to video resources for further learning.

Uploaded by

sigma231234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views28 pages

For Loop Part 1 - Easy

The document outlines lessons on string manipulation and iteration in programming, specifically focusing on the use of for loops. It includes examples and tasks for students to practice their understanding of loops, string functions, and user input. Additionally, it provides links to video resources for further learning.

Uploaded by

sigma231234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Revisit phase - Starter

Used to … Function / symbol

Change the string to .lower()


lowercase

Change the string to


uppercase .upper()
Symbol used to
concatenate 2 strings. +
Finds the length of a
string len()
Used to extract part of a
string in PSEUDOCODE:
.substring()
Created by Mr Suffar
Lesson 9 Monday, January 20, 2025

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

Iteration: The repetition of a process/


section of code.

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

Note that indenting (using the TAB key) is used to


decide which code goes inside the loop.

Created by Mr Suffar
Number of iteration
Variable

for x in range (5) :


print("Hello")
print("The end")

It will display “hello” 5 times then it will


display “The end” ONCE.

Created by Mr Suffar
Number of iteration
Variable

for y in range (3) :


name=input("Enter a name")
print("Your name is", name)
print(“Good bye")

It will ask the question 3 times and then displays the


names 3 times then it will display “Good bye” once

Created by Mr Suffar
Start from
Variable
Up to but not included

for x in range (1,11) :


print(x)

This is used if you want to use a counter. x is a variable


that will hold numbers from 1 to 10.

Created by Mr Suffar
Start from
Variable
Up to but not included

for count in range (1,6) :


print(count* 10)

This will produce the 10 times table from 1 to 5.

Created by Mr Suffar
number = int(input("Enter number"))
for i in range (number) :
print("hello")

This will display “hello” depending on the number that the


user entered. Created by Mr Suffar
number = int ( input ( "Enter number " ) )
for count in range (1,6) :
print ( number * count )

What will the above program display if the user enters


100 as the number.
• It will display the times table of the number that the
user enters (100) from 1 to 5.
Created by Mr Suffar
Tasks
Complete task 72 – 86
Then complete any unfinished tasks from previous
lessons.

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.

for count in range(1,31):


print (count * "%")

Paste your new code below with comments:

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

You might also like