Python Programming – John Zelle: Chapter 3 ex. 2

Write a program to calculate the cost per square inch of a circular pizza.

Chapter 3 Exercise 2

Python

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #Chapter 3 Exercise 2 #Write a program to calculate the cost per square inch of a circular pizza. from math import * def main(): print("This program finds the cost per square inch of a circular pizza") dia = eval(input("Please enter the diameter of the pizza: ")) cost = eval(input("Please enter the price of the pizza: ")) r = dia / 2 area = (pi * r**2) print("The cost per square inch of the pizza is", round(cost/area, 2), "cents") main() |

Run =

This program finds the cost per square inch of a circular pizza

Please enter the diameter of the pizza: 15

Please enter the price of the pizza: 10

The cost per square inch of the pizza is 0.06 cents