Você está na página 1de 5

Chapter 6: Repetition — Extra Practice

Infinite Loops

Ch06_extra01

Revise the program to create programs as follows:


Ch06_extra02
Displays the square root of the number.

Ch06_extra03
Displays the number as a percentage out of 75.

Ch06_extra04
Displays the result when 2 is raised to the power of the number.
Chapter 6: Repetition — Additional Exercises
Page 2 of 5

Conditional Loops
Ch06_extra05
Revise the program above to stop and display the message “Program has finished” when
the user enters a negative number.
Ch06_extra06
Create a program that tells users they are about to play a guessing game, where they will
try to guess a mystery letter of the alphabet (lower case letters only). Tell them “Sorry,
wrong guess” for an incorrect guess and “Congratulations, you are correct!” for a correct
guess.

Or

Ch06_extra07
Revise the previous guessing game so that there are three correct letters.
Chapter 6: Repetition — Additional Exercises
Page 3 of 5

Counted Loops
Ch06_extra08
Revise the program on page 103 of the text book to calculate the average of a person’s
six paycheques. Show dollar signs and two decimal places.

Ch06_extra09
Enter and run the following program:

% The "Ch06_extra08" program


var letter : string
put "You get 10 tries to guess the mystery letter of the alphabet (lower case only)"
for count 1: .. 10
put "Enter your guess: " ..
get letter
exit when letter = "z"
put "Sorry, wrong guess."
end for

Ch06_extra10
Revise the previous program so a wrong guess receives response in the pattern, “Sorry wrong
guess. That was guess 1.”
Chapter 6: Repetition — Additional Exercises
Page 4 of 5

Counting in Multiples
Ch06_extra11
This program tests the user’s understanding of Turing’s counting in multiples feature.

% The "Ch06_extra11" program


% Tests the user's understanding
% of Turing's counting in multiples feature
var guess : int
put “This program is going to test your
understanding of Turing’s counting in multiples
feature.”
put "It will count in 2s from 10 to 27."
put "Enter your prediction of the last result: " ..
get guess
for count : 10 .. 27 by 2
put count
end for
put "Your guess was ", guess

Ch06_extra12
Revise the previous program so that the user inputs not only the guess but also the
multiple, the start number and the stop number.
Chapter 6: Repetition — Additional Exercises
Page 5 of 5

Can you see why the following program won’t work?

% The "Ch06_extra01b" program


% Displays the tenth character in the
% collating sequence past a character input
% by the user
var character : string
loop
put "Enter a character: " ..
get character
put "The tenth character in the collating
sequence”
put “ past ", character, " is ", character + 10
end loop

Você também pode gostar