Advertisement
Guest User

Untitled

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