!
Work through this worksheet on your own.
Describe each program
Copy the code and add a comment at the top describing what it does.
Program 1
Python
x = 0 while x < 100: print(x) x = x + 2
Program 2
Python
x = input() y = 3 while y < x: print(y + 3) y = y + 1<
Program 3
Python
while number != 53:
print("Try again")
Write the code
Write Python programs for each of the following:
- Write a program that takes in a name and prints it 100 times to the display.
- Ask the user for a number. Keep looping until they enter a number greater than 50.
- Ask the user for a password. Keep looping until they enter "letmein"
- Write a program that takes in a number from the user and loops to that number.
- Write a program that asks the user a question (such as "What is the capital of France?") and loops until the user gives the correct answer.
- Write a login program that asks the user for their username and password. If the user gets their information wrong, then it asks again.
- Write a program that loops from 0 to 100, adding each number to the previous number (e.g. 2 + 3, 3 + 4, 4 + 5) and prints it to the display.
- Write a program that asks the user to enter a number until the number entered is less than 0. Until then, the program should add all other numbers up.
- Write a program to keep asking the user to enter a word until they type βstopβ. It should then display all other words concatenated together.
- Write a program to generate random numbers between 1 and 10 and keep printing them until the number 7 appears.
- Create a number-guessing game: loop until the user guesses the secret number 23. Loop until they get 23.
- Adapt the program above to generate a random number the user needs to guess.
- Loop from 1 upwards and print each number until the total of all numbers added together exceeds 500.
- Create a program that keeps generating random dice rolls (1β6) until the user has rolled three sixes.
- Create a program to ask the user to enter words. Stop when a word longer than 8 characters is entered.
- Loop and display a menu (1. Add, 2. Subtract, 3. Quit). Only stop when the user chooses 3. Using if statements, check if the user has typed in 1 or 2 and if they have ask them to enter two numbers and perform that operation on them.