Back to 课程

Computer Science GCES EDEXCEL

0% Complete
0/0 Steps
  1. Decomposition And Abstraction Edexcel
    2 主题
  2. Algorithms Edexcel
    11 主题
  3. Truth Tables Edexcel
    3 主题
  4. Binary Edexcel
    6 主题
  5. Data Representation Edexcel
    4 主题
  6. Data Storage And Compression Edexcel
    2 主题
  7. Hardware Edexcel
    5 主题
  8. Software Edexcel
    3 主题
  9. Programming Languages Edexcel
    2 主题
  10. Networks Edexcel
    7 主题
  11. Network Security Edexcel
    2 主题
  12. Environmental Issues Edexcel
    1 主题
  13. Ethical And Legal Issues Edexcel
    3 主题
  14. Cybersecurity Edexcel
    2 主题
  15. Develop Code Edexcel
    6 主题
  16. Constructs Edexcel
    4 主题
  17. Data Types And Data Structures Edexcel
    5 主题
  18. Operators Edexcel
    1 主题
  19. Subprograms Edexcel
    2 主题
课 Progress
0% Complete

Exam code:1CP2

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

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注