3.9.1. Contributed Exercises¶
Q-1: After completing the reading, what concepts are still unclear to you? If nothing is unclear, what did you find most interesting?
Consider the code below that takes two numbers and calculates the average. Before running it try to do it on a paper and use a calculator. What is the average of two numbers like: 7 and 9? Now, run the program below with these numbers. Do you get the result you expected? Obviously, your result is wrong, but Python is not complaining at all! This is because a logical or semantic mistake has been made. There is nothing wrong with the syntax, but your calculation is wrong. Fix the code below to give you the expected result every time, with any pair of numbers the user specifies.
Consider the code below. We want the user to enter the age of their dog and we want to write the program that will output the age of the dog in human years. The rule you want your program to follow is that 1 dog year is 7 human years. We wrote some code for you below, but it has a number of syntax errors. What is a syntax error (review Ch3 if needed)? Fix it to work as you would expect. For example, if my dog is 7 years old, I expect to see the following output: Your dog’s age is equivalent to 49 human years.
Use for loops to make a turtle draw these regular polygons (regular means all sides the same lengths, all angles the same). Note: your polygons can be anywhere in the window.
A hexagon (six sides)