Convert Algorithms (Edexcel GCSE Computer Science)

Revision Note

Robert Hampton

Expertise

Computer Science Content Creator

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

Exam Tip

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()

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

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

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.