Convert Algorithms (Edexcel GCSE Computer Science)

Revision Note

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

How can you convert algorithms?

  • Having a deep understanding of at least one programming language (program code) and working with high quality algorithms, it is possible to convert between them

  • In the exam students should be able to convert algorithms from:

    • Flowcharts to program code

    • Pseudocode to Program code

Examiner Tips and Tricks

Before working through the examples on this page, make sure you read through the introduction to flowcharts and pseudocode page here

Flowcharts to Program Code

Task

  • Convert the following flowchart into program code (Python)

Simple guessing number game flowchart

Program code

import random

num = random.randint(1,100) # 1

print("Welcome to the number guessing game!")

guess = int(input("Guess a number between 1 and 100: ")) # 2

while guess != num: # 3

if guess > num: # 3

print("Too high!, try again") # 4

guess = int(input("Guess a number between 1 and 100: "))

elif guess < num: # 3

print("Too low!, try again") # 4

guess = int(input("Guess a number between 1 and 100: "))

print("Good guess!") # 4

Pseudocode to Program Code

Task

  • Convert the following Pseudocode into program code (Python)

Pseudocode

temperature = input()

scale = input() "C or F"

IF scale = "C" THEN

new_scale = "F"

temperature = (temperature * 9/5) + 32

ELSE IF scale = "F" THEN

new_scale = "C"

temperature = (temperature - 32) * 5/9

ELSE

output("Invalid scale, Please enter 'C' or 'F'"

END IF

output("The temperature is ", temperature ,"degrees", new scale)

Program code

def convert_temperature():

# -----------------------------------------------------------------------

# Converts temperature between Celsius and Fahrenheit

# -----------------------------------------------------------------------

# Initialise variables

temperature = float(input("Enter a temperature value: "))

scale = input("Enter temperature scale (C or F): ").upper()

# Perform conversion

if scale == "C":

new_scale = "F"

temperature = (temperature * 9/5) + 32

elif scale == "F":

new_scale = "C"

temperature = (temperature - 32) * 5/9

else:

print("Invalid scale. Please enter 'C' or 'F'.")

return # Exit the function if invalid scale

# Display result

print(f"The temperature is {temperature:.2f} degrees {new_scale}.")

# ------------------------------------------------------------------------

# Main program

# ------------------------------------------------------------------------

convert_temperature()

Last updated:

You've read 0 of your 5 free revision notes this week

Sign up now. It’s free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Author: James Woodhouse

Expertise: Computer Science

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.