top of page
top

Python - Section 5 Practice Tasks

noun-import-1073974-FFFFFF.png

Task One: Random Numbers

Ask the user to input 4 different numbers.

​

Put the four variables in a list with square brackets and use the choice command from section 5a to randomly select one.

Example solutions:

Enter number 1: 10
Enter number 2: 20
Enter number 3: 30
Enter number 4: 40
The computer has selected 30

Enter number 1: 2023
Enter number 2: 2024
Enter number 3: 2025
Enter number 4: 2026
The computer has selected 2026

Task Two: Logging In

You will make a program for logging into a system.

 

Print a greeting then ask the user for their name.

 

Wait 2 seconds then print a simple login message with the user’s name.

 

Then print the current time (current hour and minute).

Example solutions:

Welcome to Missleton Bank
Please enter your name:
Steve Steveson
Logging you in Steve Steveson
The time is 08:02

Welcome to Missleton Bank
Please enter your name:
Gracie Jones
Logging you in Gracie Jones
The time is 15:53

Task Three: Random Wait

Generate a random number between 3 and 10 to represent seconds.

 

Print this number then print the current hour, minute and second.

​

Wait for the random number of seconds then print the current time again.

Example solutions:

The random wait will be 6 seconds.
The time is 08:17:57
The time is 08:18:03

The random wait will be 3 seconds.
The time is 08:21:39
The time is 08:21:42

Task Four: Independence Checker

Create a program that displays how many days three specific countries have been independent for. The user will choose either Fiji, Samoa or Australia and the difference between today's date and the day they become independent will be displayed.

​

  • Fiji became independent on 10th October 1970.

  • Samoa became independent on 13th December 1962.

  • Australia became independent on 1st January 1901.

​

Use the 'Today's Date' and 'Between Dates' parts of Section 5c to help you get today's date, make the other three dates and find the difference. Making Samoa's independence date would be samoadate = date(1962,12,13) for example.

Example solutions:

Enter FIJI, SAMOA or AUSTRALIA to check how long it has been independent for: AUSTRALIA
Australia has been independent for 44822 days.

Enter FIJI, SAMOA or AUSTRALIA to check how long it has been independent for: FIJI
Fiji has been independent for 19338 days.

Task Five: Square Root

Create a program that asks the user to enter a whole number.

 

Calculate the square root of the number. Round the answer down to the nearest whole number using the floor command.

Example solutions:

Enter a number: 156
The rounded down square root is 12

Enter a number: 156
The rounded down square root is 12

bottom of page