Quiz 1 Study Guide Extra Problems

More Sample practice problems

1) Write a program to compute the area of a circle given the radius entered by the user. (The area of a circle equals pi times the radius squared.) Print the area with three digits after the decimal point.

$ python circle.py
Enter the radius of the circle: 4
The area of the circle equals 50.265

2) Write a program that takes a user’s annual salary in dollars and their tax bracket, and outputs the total income taxes for the year.

$ python taxes.py
Enter your salary in dollars: 30000
Enter the percentage of your tax bracket: 15
You owe $4500.0

3) Show the output from the following code fragments:

n=10
for i in range(n):
    print(n-i)
    print("--")
print("blastoff!")
for z in range(5):
    print("2*z+1 = " +  str(2*z+1))
print("done!")
n = 6
ch = "a"
ch2 = "z"
for i in range(1, n+1):
    print(ch*i + ch2*(i-1))

4) Write a program that asks the user for a number (n), then prints out the first n even numbers n times each.

$ python3 evens.py
How high do you want to go? 6
222222
444444
666666
888888
101010101010
121212121212