Practice Exercises for Expressions
Solve
each of the practice exercises below. Each problem includes three
CodeSkulptor links: one for a template that you should use as a starting
point for your solution, one to our solution to the exercise, and one
to a tool that automatically checks your solution.
- There are feet in a mile. Write a Python statement that calculates and prints the number of feet in miles. Miles to feet template --- Miles to feet solution --- Miles to feet (Checker)
- Write a Python statement that calculates and prints the number of seconds in hours, minutes and seconds.Hours to seconds template --- Hours to seconds solution --- Hours to seconds (Checker)
- The perimeter of a rectangle is , where and are the lengths of its sides. Write a Python statement that calculates and prints the length in inches of the perimeter of a rectangle with sides of length and inches. Perimeter of rectangle template ---Perimeter of rectangle solution --- Perimeter of rectangle (Checker)
- The area of a rectangle is , where and are the lengths of its sides. Note that the multiplication operation is not shown explicitly in this formula. This is standard practice in mathematics, but not in programming. Write a Python statement that calculates and prints the area in square inches of a rectangle with sides of length and inches. Area of rectangle template Area of rectangle solution Area of rectangle (Checker)
- The circumference of a circle is where is the radius of the circle. Write a Python statement that calculates and prints the circumference in inches of a circle whose radius is inches. Assume that the constant . Circumference of circle template --- Circumference of circle solution --- Circumference of circle (Checker)
- The area of a circle is where is the radius of the circle. (The raised in the formula is an exponent.) Write a Python statement that calculates and prints the area in square inches of a circle whose radius is inches. Assume that the constant . Area of circle template --- Area of circle solution --- Area of circle (Checker)
- Given dollars, the future value of this money when compounded yearly at a rate of percent interest for years is . Write a Python statement that calculates and prints the value of dollars compounded at percent interest for years. Future value template --- Future value solution --- Future value (Checker)
- Write a single Python statement that combines the three strings , and (plus a couple of other small strings) into one larger string and prints the result. Name tag template --- Name tag solution --- Name tag (Checker)
- Write a Python expression that combines the string from the string and the number and then prints the result (Hint: Use the function to convert the number into a string.) Name and age template --- Name and age solution --- Name and age (Checker)
- The distance between two points and is . Write a Python statement that calculates and prints the distance between the points and . Point distance template --- Point distance solution --- Point distance (Checker)