Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.6 kB
2
Indexable
Never
""""
sampo perunka comp sci 1
geometrisien kuvioiden laskuri
"""

def read_input(question):
    """virheentarkastus ettei kukaan laita vääriä arvoja"""
    while True:
        asd = input(question)
        try:
            asd = float(asd)
            if asd > 0:
                return asd
            else:
                pass

        except ValueError:
            pass

def square1(value):
    """suuret määrät spagettii aaaaaaaaaaaaaaa"""
    halkaisija = value * 4
    return halkaisija
def square2(value):
    """vähän lisää spagettia lisää aaaaaaaaaaaaaa"""
    surface_area = value * value
    return surface_area

def rectangle1(side1, side2):
    """laskee suorakulmion halkaisijan spagetilla"""
    halkaisija = side1 * 2 + side2 * 2
    return halkaisija

def rectangle2(side1, side2):
    """Calculates the surface area for square"""
    surface_area = side1 * side2
    return surface_area

def circle1(radius):
    """laskee ympyrän halkaisijan"""
    PI = 3.14159265359
    halkaisija = 2 * PI * radius
    return halkaisija
def circle2(radius):
    """Calculates the surface area for circle"""
    PI = 3.14159265359
    surface_area = PI * (radius ** 2)
    return surface_area
def menu():
    """
    Print a menu for user to select which geometric pattern to use in calculations.
    """
    while True:
        answer = input("Enter the pattern's first letter or (q)uit: ")

        if answer == "s":
           squares_side = read_input("Enter the length of the square's side: ")
           print(f"The circumference is {(square1(squares_side)):.2f}")
           print(f"The surface area is {(square2(squares_side)):.2f}")
           pass

        elif answer == "r":
           rectangle_side1 = read_input("Enter the length of the rectangle's side 1: ")
           rectangle_side2 = read_input("Enter the length of the rectangle's side 2: ")
           print(f"The circumference is {(rectangle1(rectangle_side1,rectangle_side2)):.2f}")
           print(f"The surface area is {(rectangle2(rectangle_side1,rectangle_side2)):.2f}")
           pass

        elif answer == "c":
            circe_radius = read_input("Enter the circle's radius: ")
            print(f"The circumference is {(circle1(circe_radius)):.2f}")
            print(f"The surface area is {(circle2(circe_radius)):.2f}")
            pass

        elif answer == "q":
           return

        else:
            print("Incorrect entry, try again!")

        # Empty row for the sake of readability.
        print()


def main():
    menu()
    print("Goodbye!")


if __name__ == "__main__":
    main()