top of page
top

Python - Section 6 Practice Tasks

noun-loop-6036209-FFFFFF.png

Task One: Odd Numbers

Use a for loop to print all odd numbers between 50 and 70.

​

You will need to use three values in the range brackets, including a step.

​

Requirements for full marks:

  • A comment at the start to explain what a for loop is.

  • Use just two lines of code.

Example solution:

51
53
55
57
59
61
63
65
67
69

Task Two: Fish Rhyme

Use two separate for loops and some additional print lines to output this nursery rhyme: "1, 2, 3, 4, 5, Once I caught a fish alive, 6, 7, 8, 9, 10 then I let it go again" in the format shown.

​

Requirements for full marks:​

  • Two for loops and two additional print lines (6 lines total).

Example solution:

1
2
3
4
5
Once I caught a fish alive.
6
7
8
9
10
Then I let it go again.

Task Three: Username & Password

Create a program using a while loop that keeps asking a user to enter a username and a password until they are both correct. It may be easier to use a while True loop

​

You will need to use the and command in an if statement within the loop.​

​

Requirements for full marks:

  • A comment at the start to explain what a while loop is.

Example solution:

Enter username: Ben43
Enter password: hamster
Incorrect, please try again.

Enter username:
Ben44
Enter password: ben123
Incorrect, please try again.

Enter username:
Ben43
Enter password: ben123
Correct
Correct login. Welcome Ben43

noun-6128802-FFFFFF.png

Task Four: Colour or Number

Use a while True loop to let the user enter either A, B or C.

​

A lets them guess a secret colour

​​​

B lets them guess a secret number.

​

C breaks the loop, ending the program.

Example solution:

Enter A to guess a colour, B to guess a number, C to quit: A
Guess the colour: green
Incorrect!

Enter A to guess a colour, B to guess a number, C to quit:
A
Guess the colour: pink
Correct!

Enter A to guess a colour, B to guess a number, C to quit:
B
Guess the number: 4
Incorrect!

Enter A to guess a colour, B to guess a number, C to quit:
C
Quitting program...

bottom of page