Question 1
Write a function called print_pyramid() which takes a single integer argument height
and displays a pyramid of this height made up of "*" characters on the screen in a function.
Limit the user to enter only number from ONE (1) to FIFTEEN (15). A sample screen is as
below:
How high would you like the pyramid to be? 5
*
**
***
****
*****
****
***
**
*
Your program should prompt the user whether he/she would like to print another pyramid. If the
user chooses Yes, your program should repeat the above steps and print another pyramid. If the
user chooses No, terminate the program. You may consider using the following sample screen:
Do you want to print another pyramid (Y/N)? Y
How high would you like the pyramid to be? 2
*
**
*
Question 2 (2.5 marks)
In an election, TEN (10) candidates are contesting and ONE THOUSAND (1000) voters are
eligible for voting. The voters’ election is done at random. The number of votes will be randomly
generated by the program. Write a program that displays the number of votes each candidate got
and the winner of the election. Note that the output should be different every time the program is
executed. A sample screen is as below:
Candidate Number Number of votes
1 125
2 12
3 78
4 350
5 1
6 87
7 36
8 14
9 78
10 219
慕的地8271018
DIEA
HUX布斯
相关分类