# Chapter 8 Exercises¶

1. Fix the 5 syntax errors in the code below to print a countdown of the numbers from 10 to 0.

Show Comments
2. The following code will loop infinitely. Make one change that will make it loop only 5 times.

Show Comments
3. Make 5 changes to the code below to correctly print a count up from -10 to 0.

Show Comments
4. Fix the errors in the code below so that it uses 2 loops to print 8 lines of *.

Show Comments
5. Finish lines 1 and 5 so that the following code correct prints all the values from -5 to -1.

Show Comments
6. Complete the code on lines 4 and 6 so that it prints the number 6.

Show Comments
7. The code below is supposed to print an estimate of the square root. But, the indention is wrong on 4 lines. Fix it.

Show Comments
8. The function currently takes a start and stop argument and uses a for loop to find the sum of all the numbers between them (inclusive). Change the for loop to a while loop while still using the parameters.

Show Comments
9. The program below is supposed to print the times tables for 1 to 3, but there are 5 errors. Fix the errors.

Show Comments
10. Rewrite the code that prints the times tables for 1 to 3 using a while loop and a for loop instead of two for loops.

Show Comments
11. Rewrite the following code to use a while loop instead of a for loop.

Show Comments
12. Fix the errors so that the code gets the average of the numbers from 1 to 10.

Show Comments
13. Rewrite the following code to use a while loop instead of a for loop.

Show Comments
14. The code below currently enters a loop where it keeps printing “Even”. Fix the code so that it prints “Even” and “Odd” for numbers 0 to 9.

Show Comments
15. Modify the code below to create a function that will take numbers as input until you enter a negative number and then will return the average of the numbers.

Show Comments
16. Fix and change the code so it prints a table of division instead of multiplication for -10 to -1.

Show Comments
17. Create a function to calculate and return the sum of all of the even numbers from 0 to the passed number (inclusive) using a while loop.

Show Comments
18. Write a procedure that takes a user input and keeps asking for a user input until the input is “Hello”. If the input is not “Hello”, it should print “This is your n wrong try.” where n is the number of times they have put an input in. If they type “Hello”, the procedure should print “Success!”. Hint: != means does not equal

Show Comments
19. Create a procedure to print stars and spaces in a roughly square pattern and have it take as input the number of stars on a side. Use a nested loop to do this.

Show Comments
20. Write a procedure that takes an int argument and uses a while loop to create a right-triangle like shape out of *. The first row should have 1 star and the last should have n stars where n is the argument passed.

Show Comments
Next Section - Exam Questions for Chapters 7 and 8