Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import math
  2. print
  3. def hello():
  4. print("Hello!")
  5.  
  6. def area(width, height):
  7. return width * height
  8. def welcome(name):
  9. print("Welcome,", name)
  10. def circle(radius):
  11. return math.pi * radius ** 2
  12. def square(width):
  13. return area( width , width)
  14. def pos_input(prompt):
  15. number = float(input(prompt))
  16. while number <= 0:
  17. print("The number must be positive.")
  18. number = float(input(prompt))
  19. return number
  20.  
  21. def options():
  22. print("To calculate the area of a square, press s.")
  23. print("To calculate the area of a rectangle, press r.")
  24. print("To calculate the area of a circle, press c.")
  25. print("To quit, press q.")
  26.  
  27. name = input("Your name: ")
  28. hello()
  29. welcome(name)
  30. options()
  31. choice = "x"
  32.  
  33. while choice != "q":
  34. choice = input("Please enter your choice: ")
  35. if choice == "s":
  36. width = pos_input("Length of square side: ")
  37. print("The area of this square is", square(width))
  38. options()
  39.  
  40. elif choice == "r":
  41. width = pos_input("Please enter the width of the rectangle: ")
  42. height = pos_input("Please enter the height of the rectangle: ")
  43. print("The area of the rectangle is:", area(width, height))
  44. options()
  45. elif choice == "c":
  46. radius = pos_input("Please enter the radius of the circle: ")
  47. print("The area of the circle is", circle(radius))
  48. options()
  49. elif choice != "q":
  50. print("Invalid choice.")
  51. options()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement