Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- print
- def hello():
- print("Hello!")
- def area(width, height):
- return width * height
- ## poistettu kokonaan square-metodi
- def welcome(name):
- print("Welcome,", name)
- def circle(radius):
- return math.pi * radius ** 2
- def pos_input(prompt):
- number = float(input(prompt))
- while number <= 0:
- print("The number must be positive.")
- number = float(input(prompt))
- return number
- def options():
- print("To calculate the area of a square, press s.")
- print("To calculate the area of a rectangle, press r.")
- print("To calculate the area of a circle, press c.")
- print("To quit, press q.")
- name = input("Your name: ")
- hello()
- welcome(name)
- options()
- choice = "x"
- while choice != "q":
- choice = input("Please enter your choice: ")
- if choice == "s":
- width = pos_input("Length of square side: ")
- print("The area of this square is", area(width, width)
- options()
- elif choice == "r":
- width = pos_input("Please enter the width of the rectangle: ")
- height = pos_input("Please enter the height of the rectangle: ")
- print("The area of the rectangle is:", area(width, height))
- options()
- elif choice == "c":
- radius = pos_input("Please enter the radius of the circle: ")
- print("The area of the circle is", circle(radius))
- options()
- elif choice != "q":
- print("Invalid choice.")
- options()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement