Sec8 Programming Rev #3
Subject :
CS
Austin Heights Private and International School
Year Group
:
Y10 CS Grp-G
Name:
Leong Yee Yi
Worksheet No. :
Sec 8 – Programming
Rev #3
Section 8: Programming Rev #3
1. You have £200 to spend on your birthday.
Write a program that will ask you to enter the price of each present on your wish list until your total is over
£200. The program should produce the output shown.
Pseudocode
DECLARE Price : Real
DECLARE Totalprice : REAL
Totalprice 0
OUTPUT “please enter the price of present”
WHILE Totalprice <= 200 DO
INPUT Price
Totalprice Totalprice + Price
ENDWHILE
OUTPUT “Limit Exceeded”
OUTPUT “You can’t include the $”+Price+“ present”
Program code
totalprice = 0
print ("please enter your price of present")
while totalprice <= 200:
price = float(input(""))
totalprice = totalprice + price
print ("Limit Exceeded")
print ("You can't include the $" + str(price) + " present")
Prepared by: GYZ/AHIS/2025
TOGETHER WE EXCEL
Page 1
Sec8 Programming Rev #3
Prepared by: GYZ/AHIS/2025
TOGETHER WE EXCEL
Page 2
Sec8 Programming Rev #3
2. Nonsense sentences is a game where a group of friends take turns to type a word each to generate a
sentence. The first person starts with an adjective. The following players can keep adding adjectives or
type a noun. After the noun is typed the next person types a verb and then there are more adjectives until
another noun is typed. The following person must type in ‘end’.
Write a program that inputs a series of words until ‘end’ is input and then outputs the nonsense sentence.
As nonsense sentences is a game, your program can leave the players to follow the rules. No punctuation
is required.
Test your program with the following input: Yellow Jolly Chair Swallows Tasty Sand end
Pseudocode
DECLARE word : STRING
DECLARE X : STRING
DECLARE sentence : STRING
sentence ← " "
INPUT word
WHILE word <> "end" DO
sentence ← sentence& " " & word
INPUT word
ENDWHILE
OUTPUT sentence
Program code
sentence = ""
word = input("please enter a word: ")
while word != "end":
sentence = sentence+" "+word
word = (input("please enter a word: "))
print (sentence)
Prepared by: GYZ/AHIS/2025
TOGETHER WE EXCEL
Page 3
Sec8 Programming Rev #3
3. Use iteration to print the following:
(a)
(b)
Prepared by: GYZ/AHIS/2025
for x in range (1,6):
print("*"*x)
for i in range (1, 6):
for j in range (i, 0, -1):
print(j, end=" ")
print ("")
TOGETHER WE EXCEL
Page 4