Wednesday 1 July 2015

15. Pseudocode and built-in subprograms: random function






Activity 14.1
Pseudocode
Pseudocode, or ‘mock’ code, is another way of describing a program. You will need a copy of the pseudocode used in this course (Appendix B of the specification) to answer thesequestions.

What does this pseudocode do?
RECEIVE myName FROM (STRING) KEYBOARD
RECEIVE myAge FROM (INTEGER) KEYBOARD
SET AgeInTen TOmyAge + 10
SEND myName “will be” AgeInTen “in 10 years time” TO DISPLAY

Write the Python code for this program.
Activity 14.2
What does this pseudocode do?
SET score TO 119
IF score < 50 THEN SEND “You have lost” TO DISPLAY
ELSE SEND “You have won” TO DISPLAY
END IF

Write the Python code for this program.
Activity 14.3
random() function
Copy and run this program code:

Run the program a few times. What does it do?
What is meant by ‘import random’?
What happens if you alter the values to 1, 100?
Activity 14.4
Write a program that acts like a dice. After each ‘throw’ of the dice it should ask if the playerwishes to continue and stop when they enter ‘Y’.
Activity 14.5
Write a program that gives the user 10 chances to guess a number between 1 and 10. It then compares their answer with a randomly generated number and stops the program when the number generated matches the number guessed or when the user is out of guesses.

No comments:

Post a Comment