Advertisement
Guest User

Untitled

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