• Home
• Contact Me
•
Aeries Portal
• Royal High School
• Simi Valley USD

AP Statistics

• Course Calendar
• Chapter Notes
• Practice Tests

AP Comp-Sci
Course Content
• Programs
• Practice Tests

CP Statistics
• Course Calendar
• Chapter Notes
• Practice Tests

Algebra
Geometry

Math Power

Computer Programming Unit 3 Programs
Looping Statements

 1. Write a program that prints a given word a specified number of times on the screen. Prompt the user for the word and the number of times to print it. Display the results with each version of the word and the current count on a separate line. For example, if the word is “HELLO” and the number is 3, the output would be: HELLO 1 HELLO 2 HELLO 3 2. Write a program that will print a table of squares and cubes for the integers from 1 to 10. The output should look roughly like the following. X     X^2    X^3 1       1      1 2       4      8 3       9     27 Etc   Etc    Etc
 3. Write a program that displays the Fahrenheit equivalents for the Celsius temperatures from 20 to 30 degrees. To convert Celsius to Fahrenheit, we use the formula F = 1.8 * C + 32, where C = Celsius temperature and F = Fahrenheit. Output as shown below (1 dec. place): Output should appear as follows:    Cels    Fahr      20    68.0      21    69.8      22    71.6     Etc     Etc 4. Assume that the height of a rocket h (in feet) at a given time t (in seconds) can be found by the equation h = 16t^2-75t+10. Write a program that will display a table of heights for 5-second intervals from 0 to 60 seconds. Output should appear as follows:   Time   Height      0       10      5       35     10      860    Etc      Etc
 5. Write a program to accept a positive integer, say X, and print the following. For example, if X = 6, the output will be: 6 + 5 + 4 + 3 + 2 + 1 = 21 6. Write a program to determine the number of even and odd numbers as well as the average of numbers entered by the user. The program should ask how many integers to be entered, and then allow the user to enter the integers, using a loop. As the integers are entered, keep track of how many are even and how many are odd. At the end, display the results as shown in the example below. You may assume that the user will only enter positive integers. Sample Run of the Program (input values are in bold type): How many numbers will be entered: 4 Enter number 1: 10 Enter number 2: 11 Enter number 3: 18 Enter number 4: 20 Evens: 3 Odds: 1 Average: 14.75
 7. Write a program that simulates flipping a coin a given number of times. Count the number of heads and tails that come up and output the results as counts. See the example below: Sample Run of the Program (input values are in bold type): How many flips would you like: 25 Heads: 15 Tails: 10 8. Write a program that will simulate 1000 rolls of a 6-sided die. Count the number of 1’s, 2’s 3’s etc.... Output the results in a table as shown below: 1: 161 2: 184 3: 160 4: 175 5: 147 6: 173
 9. Write a program that creates a multiplication quiz for the user with the integers from 1 to 20. The program will ask the user 10 multiplication questions by randomly selecting two integers in the range 1 to 20. The user’s answers should be checked for right or wrong, with counts kept for each. Also, display a message telling the user whether or not each answer is correct. At the end of the quiz, the program should tell the user how many problems they got right. Sample Run of the Program (input values are in bold type): Question #1: 10 x 5 Your Answer: 50 That’s Correct! Question #2: 12 x 11 Your Answer: 121 That’s Wrong! Etc... You got 7 correct! 10. Write a program that will allow the user to play a guessing game with the computer. The computer will pick a random number from 1 to 100. The user then is asked to guess the computer’s number. If the user is right, say so, output the number of guesses it took and end the program. If the user is wrong, state whether the guess is TOO LOW or TOO HIGH and allow the user to guess again, until they get it right. Sample Run of the Program (input values are in bold type): Guess #1: 50 TOO HIGH. TRY AGAIN. Guess #2: 25 TOO LOW. TRY AGAIN. Guess #3: 37 TOO HIGH. TRY AGAIN. Guess #4: 32 RIGHT ON! YOU GOT IT IN 4 GUESSES.
 11. Write a program that uses a WHILE loop to allow the user to enter integers until a 0 is entered. After the 0 is entered, the sum and average of the integers should be displayed. BE SURE TO NOT INCLUDE THE 0 AS ONE OF THE NUMBERS. See an example below: Enter #1: 3 Enter #2: 5 Enter #3: 1 Enter #4: 8 Enter #5: 0 Sum = 17 Avg = 4.25 12. Write a program that will allow you to play a game of Rock-Paper-Scissors against the computer. In the game, the computer randomly selects Rock, Paper or Scissors. You also make a choice. If you both choose the same object, it is a tie, and the game continues. Otherwise, the winner is based on the following: ROCK beats SCISSORS, SCISSORS beats PAPER and PAPER beats ROCK. Use a random number from 1 to 3 to make the computer’s choice. You will make your choice by entering a number from 1-3 based on the following: 1 = ROCK 2 = PAPER 3 = SCISSORS Sample Run of the Program (input values are in bold type): Your choice: 2 PAPER Computer: PAPER Result: TIE Your choice: 3 SCISSORS Computer: ROCK Result: Computer Wins!