0% found this document useful (0 votes)
44 views

WHILE Loop Tasks

Uploaded by

avantica2802
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)
44 views

WHILE Loop Tasks

Uploaded by

avantica2802
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/ 21

WHILE Loop Tasks

105. Create a program that:


• Asks the user to input a password.
• If password is correct, display correct password.
• If password is incorrect, display incorrect password.
• The program will repeatedly ask the same question until the correct answer is entered.
• Assume the correct password is: “csgo1234”
Paste your code below:

Clue under here!

https://youtu.be/ZnUOqSNizJ4
105. Create a program that:
• Asks the user to input a password.
• If password is correct, display correct password.
• If password is incorrect, display incorrect password.
• The program will repeatedly ask the same question until the correct answer is entered.
• Assume the correct password is: “csgo1234”
Paste your code below:
password = input("Enter a password")
while password != "csgo1234":
print("Incorrect password")
password = input("Enter a password")
print("Correct password")

https://youtu.be/ZnUOqSNizJ4
106. Create a program that:
• Asks the user to enter 2 numbers that are the equal to each other.
• Display the first number multiplied by the second number if they are both the same.
• The program will repeatedly ask the user for 2 numbers until both numbers are equal
to each other.
Paste your code on the next slide:

Clue under here!

https://youtu.be/xjuCDg6zqt0
106. Create a program that:
• Asks the user to enter 2 numbers that are the equal to each other.
• Display the first number multiplied by the second number if they are both the same.
• The program will repeatedly ask the user for 2 numbers until both numbers are equal
to each other.
Paste your code on the next slide:
number1 = int(input("Enter a number"))
number2 = int(input("Enter another number"))
while number1 != number2:
number1 = int(input("Enter a number"))
number2 = int(input("Enter another number"))
print(number1 * number2)

https://youtu.be/xjuCDg6zqt0
107. Use a while loop to create the 2 times table up to 100. Display “You have finished”
when you get to the number 100.
Paste your code below:

Clue under here!

https://youtu.be/AotoYo5HfKI
107. Use a while loop to create the 2 times table up to 100. Display “You have finished”
when you get to the number 100.
Paste your code below:
number = 0
while number < 101:
print(number)
number = number + 2
print("You have finished")

https://youtu.be/AotoYo5HfKI
108. Display “Hey” and “Bye” on separate lines 1000 times using a while loop.
Paste your code below:

Clue under here!

https://youtu.be/3NjSTFSNALk
108. Display “Hey” and “Bye” on separate lines 1000 times using a while loop.
Paste your code below:
number = 0
while number < 1000:
print("Hey")
print("Bye")
number = number + 1

https://youtu.be/3NjSTFSNALk
109. Create a program that:
• Asks the user to input 4 names.
• Displays “You have entered 4 names” when all 4 names has been entered.
• Use a while loop to repeat the question 4 times to enter 4 names in total.
Paste your code below:

Clue under here!

https://youtu.be/8oqn709M2b0
109. Create a program that:
• Asks the user to input 4 names.
• Displays “You have entered 4 names” when all 4 names has been entered.
• Use a while loop to repeat the question 4 times to enter 4 names in total.
Paste your code below:
number = 0
while number < 4:
name = input("Enter a new name")
print(name)
number = number + 1
print("You have entered 4 names")

https://youtu.be/8oqn709M2b0
110) Create a program that:
• Asks the user to enter a number.
• Adds that number to a total which starts from 0.
• Displays the total.
• The program repeats until the total is over 50.
Paste your code below:

Clue under here!

https://youtu.be/4ciL9cQLn0s
110) Create a program that:
• Asks the user to enter a number.
• Adds that number to a total which starts from 0.
• Displays the total.
• The program repeats until the total is over 50.
Paste your code below:
total = 0
while total < 51:
number = int(input("Enter a number"))
total = total+number
print(total)
https://youtu.be/4ciL9cQLn0s
111. Code the following flowchart in python:

Clue under here!

https://youtu.be/9Hx2vy8Tong
Paste your code below:
111. Code the following flowchart in python:

https://youtu.be/9Hx2vy8Tong
Paste your code below:

firstname = input("Enter your firstname")


surname = input("Enter your surname")
while firstname != "Michael" and surname != "Jackson":
firstname = input("Enter your firstname")
surname = input("Enter your surname")
112. Create a program that:
• Asks the user for a username.
• If the username is less than 8 characters long, display “username is invalid” and repeat
the question until a valid username is entered.
• Asks the user for a password.
• If the password is less than 8 characters long OR greater than 15 characters, display
“Password is invalid” and repeat the question until a valid password is entered.
Paste your code below:

Clue under here!

https://youtu.be/g0ZzxWfTUDc
112. Create a program that:
• Asks the user for a username.
• If the username is less than 8 characters long, display “username is invalid” and repeat
the question until a valid username is entered.
• Asks the user for a password.
• If the password is less than 8 characters long OR greater than 15 characters, display
“Password is invalid” and repeat the question until a valid password is entered.
Paste your code below:
username = input("Enter username")
while len(username) < 8:
print("username is invalid")
username = input("enter another username")
print("Your username has been accepted")
password = input("Enter a password")
while len(password) < 8 or len(password) > 15:
print("Password is invalid")
password = input("enter another password")
print("Your password has been accepted") https://youtu.be/g0ZzxWfTUDc
113. Create a program that:
• Asks the user to input a password.
• If password is correct, display correct password.
• If password is incorrect, display incorrect password.
• Repeat the question until the user enters the correct password or reaches 4 attempts.
After 4 incorrect attempts, display "Locked"
• Assume the password is: "Rashford"
Paste your code below:

Clue under here!

https://youtu.be/Ps1Y_b_cQUY
113. Create a program that:
• Asks the user to input a password.
• If password is correct, display correct password.
• If password is incorrect, display incorrect password.
• Repeat the question until the user enters the correct password or reaches 4 attempts.
After 4 incorrect attempts, display "Locked"
• Assume the password is: "Rashford"
Paste your code below:
attempts = 0
while attempts != 4:
password = input("Enter password")
if password == "Rashford":
print("Correct")
attempts = 4
else:
print("Incorrect")
attempts = attempts + 1
if attempts ==4:
print("Locked")
https://youtu.be/Ps1Y_b_cQUY
114. Borednite is a new game. When a character takes damage in the game, their health bar goes down.
The health bar starts to increase (regenerate) 5 seconds from the last time a player was hit and by 15%
per second. At 100%, the health bar has 500 health points.
Create an algorithm that:
• Asks the user how many health points they were on since the last time they got attacked.
• Calculates and display how many seconds it will take before the user reaches 100% health (500
points) from the last time they got attacked.
Hint: Use a while loop.
Paste your code below:

Clue under here!

https://youtu.be/unyUmU3Kj8U
114. Borednite is a new game. When a character takes damage in the game, their health bar goes down.
The health bar starts to increase (regenerate) 5 seconds from the last time a player was hit and by 15%
per second. At 100%, the health bar has 500 health points.
Create an algorithm that:
• Asks the user how many health points they were on since the last time they got attacked.
• Calculates and display how many seconds it will take before the user reaches 100% health (500
points) from the last time they got attacked.
Hint: Use a while loop.
Paste your code below:
health = int(input("What is your health points when you got attacked?"))
seconds = 5
while health < 500:
health = health+ (500*0.15)
seconds = seconds+1
print("It will take",seconds,"before you reach 100% health")

https://youtu.be/unyUmU3Kj8U

You might also like