Asset table template for iMedia, Assignments of Computer science

iMedia coursework asset table template

Typology: Assignments

2025/2026

Uploaded on 06/25/2026

archie-brooks
archie-brooks 🇬🇧

1 document

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
KS4 - Programming
Lesson 22 - Structured programming
Activity sheet
Improve the code
Worked example .
Code before
1
2
3
4
5
6
7
to_guess = 3
not_guessed = True
while not_guessed:
print("Guess a number")
number = int(input())
if number == to_guess:
break
Code after
1
2
3
4
5
6
7
to_guess = 3
not_guessed = True
while not_guessed:
print("Guess a number")
number = int(input())
if number == to_guess:
not_guessed = False
Page 1 Last updated: 17-05-21
pf3
pf4
pf5

Partial preview of the text

Download Asset table template for iMedia and more Assignments Computer science in PDF only on Docsity!

Lesson 22 - Structured programming

Improve the code

Worked example.

Code before 1 2 3 4 5 6 7 to_guess = 3 not_guessed = True while not_guessed: print("Guess a number") number = int(input()) if number == to_guess: break Code after 1 2 3 4 5 6 7 to_guess = 3 not_guessed = True while not_guessed: print("Guess a number") number = int(input()) if number == to_guess: not_guessed = False

Lesson 22 - Structured programming

Tasks.

  1. Copy and paste the ‘before’ code into your development environment
  2. Edit the code so that the block only has one entry point and one exit point
  3. Paste the improved code into the ‘after’ box Note: The program should perform in exactly the same way when executed. Tip: Use the worked example above as a guide.

Program 1

Code before 1 2 3 4 5 6 7 8 9 10 11 def and_function(a, b): if a == True and b == True: return True else: return False one = 4 == 4 two = 2 == 2 print(and_function(one, two))

Lesson 22 - Structured programming

Program 3

Code before 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 def password_check(): password = "12345" entered_pass = "" pass_not_valid = password != entered_pass attempts = 0 while pass_not_valid and attempts < 3: print("Enter a password:") entered_pass = input() attempts = attempts + 1 if password == entered_pass: break if password != entered_pass: return "Access Denied" else: return "Access Granted" print(password_check())

Lesson 22 - Structured programming Code after 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 def password_check(): password = "12345" entered_pass = "" pass_not_valid = password != entered_pass attempts = 0 while pass_not_valid and attempts < 3: print("Enter a password:") entered_pass = input() attempts = attempts + 1 if password == entered_pass: pass_not_valid = False if password != entered_pass: a = "Access Denied" else: a = "Access Granted" return a print(password_check()) Resources are updated regularly — the latest version is available at: ncce.io/tcc.