Python For GCSE
Section B Exercises

Task 1

In a school test, you need to score more than 20 marks to pass the test. The program asks the user to enter a test score. If they score more than 20 marks, the user is told that the test has been passed. Here is a Scratch program that does this job,

Scratch Program

Write a Python program that performs the same task.

Python Code

Task 2

In a school test, you need to score more than 20 marks to pass the test. The program asks the user to enter a test score. If they score more than 20 marks, the user is told that the test has been passed, if not they are told that they have failed. Here is a Scratch program doing the job.

Scratch Program

Write a Python program that performs the same task.

Python Code

Task 3

A person can legally drive a car if they are 17 or over and have passed their driving test. The program asks the user for their age and if they have passed their test. These two pieces of information are used to determine if the person is allowed to drive or not.

Scratch Program

The key part of this program is the AND block. Look at the Python code and finish off by replacing the red splodges with the correct code.

Python Code

Task 4

A program has a menu of choices. The user must enter a number from 1 to 5 in order to access the menu choices. If the user enters a number lower than 1 or higher than 5, the program tells them they have made a mistake.

Scratch Program

When you test this program, you might notice that it doesn't work properly if you enter letters. The key part of this program is the OR block. As before, complete the Python code,

Python Code

Task 5

Write a program that asks the user for two numbers. Depending on the numbers entered, output one of the following messages.

  • The two numbers are equal
  • The first number is larger than the second
  • The second number is larger than the first

Python Code

Task 6

Ask the user to enter the current month, the program should output whether the month is in Winter, Spring, Summer or Autumn.

Task 7

The basic pseudocode for determining whether a year is a leap year or common year is,

if year is not divisible by 4 then
   common year
else if year is not divisible by 100 then
   leap year
else if year is divisible by 400 then
   leap year
else
   common year

Write a Python program that tells you whether an integer input by the user represents a leap year or not.

Task 8

Ask the user to input the number of a month. Display the name of the corresponding month.

Task 9

Write a program that allows the user to enter an examination score as an integer in the range 0 - 65. Convert the score into a grade using the boundaries specified below.

A - 47, B - 42, C - 37, D - 33, E – 29

Task 10

Write a program which asks the user to enter their name. If the name that is entered is the same as yours, tell them that they have a cool name. If not, tell them that they should consider changing their name from whatever their name is to whatever your name is.

Task 11

The following table shows a list of ages and one of the legal rights that a person gets when they reach that age. Use this information to write a program where the user can enter their age and see a list of the legal rights they have.

  • 12: See a 12A-rated film at the cinema without an adult.
  • 14: Have a job which can be described as 'light work'.
  • 15: See a 15-rated film at the cinema without an adult.
  • 16: Enter a pub on your own. You cannot buy alcoholic drinks.
  • 17: Donate blood.
  • 18: Serve on a jury.
  • 21: Adopt a child

Task 12

Write a program that simulates the rolling of two dice. If the player rolls a double, they get to roll one die as a bonus. The player's final score is the total of all of the dice rolls.

Task 13

Write a program that simulates the rolling of two dice. If the player rolls a double, they get an extra roll of a single die. If they roll an even number, the number is doubled and added to their previous total. If they roll an odd number, the number is simply added to their previous total.

Task 14

Write a program that requires the user to enter a number corresponding to a month of the year. If they enter 2, ask them to enter a Year. Check if the year is a leap year or not and report how many days there will be in the month.