0% found this document useful (0 votes)
2 views

Programming Practice

The document outlines several programming exercises, including a dice game simulation using Python, a game involving Loopy Lou and trolls, and a calculation of grains of wheat on a chessboard. Each program includes specific tasks such as completing trace tables and understanding algorithms. The exercises aim to enhance programming skills and algorithmic thinking.

Uploaded by

Yasmin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programming Practice

The document outlines several programming exercises, including a dice game simulation using Python, a game involving Loopy Lou and trolls, and a calculation of grains of wheat on a chessboard. Each program includes specific tasks such as completing trace tables and understanding algorithms. The exercises aim to enhance programming skills and algorithmic thinking.

Uploaded by

Yasmin
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

21st November 2024

Programming practice
Program 1 Exhibit 1.

• Develop a python program that


simulates a dice game. The flowchart
represents the algorithm in Exhibit 1.
• A Random number is generated using
the random function. The algorithm
calculates a player’s score when it is
their turn. Ruby and Sam play the game.
Program 2
• The following program code is part of a game in which Loopy Lou is engaged with trolls, dealing deathly blows in all directions to overcome
the evil trolls but taking considerable punishment herself until she is fatally injured.
• Complete the next 4 rows in the following trace table.

injuries trolls lives lives > 0


0 4 30 True
Program 3
• When the creator of the game of chess showed his invention to the ruler of the country. The ruler was so pleased that he

gave the inventor the right to name his prize for the invention. The man, who was very clever, asked the king for the

following as his prize:

• One grain of rice on the first square

Two grains on the second square

Four grains on the third square – and doubling for each square thereafter.

• A programmer decides to find out how many grains of wheat the inventor will end up with. He tests the program with

just 6 squares of the chessboard.

• The program is shown below. Complete the trace table to show the total number of grains of wheat received for the first

6 squares of the chessboard.


Program 3
print("How many grains of wheat will be on each square?")
grains = 1
grains total n
total = 1
1 1 2
for n = 2 to 6
grains = grains * 2
total = total + grains
print(total)
next n
Program 4
• Draw a trace table to follow through this algorithm. State the output if the user enters 21, 10, 6, 5, 30, 9
total n a b OUTPUT
total = 0
for n = 1 to 6
a = input("Input next value: ")
if a < 10
b = a / 10
print(b)
total = total + b
endif
next n
print(total)

You might also like