Answer to Question #291910 in Python for Micky

Question #291910

a) Write a program using functions to imitate a university canteen ticketing system. A student is required to enter their registration number and pin to access the food menu and make payments. Also a student is allowed to enter only two times a wrong pin before account is blocked.



b) Demonstrate using functions to calculate the area and perimeter as right angled triangle. Given that the perimeter of a triangle is the sum of all three sides and the hypotenuse of a triangle is obtained by sqtr((len * len)+(height * height)) where sqtr() is in a built-in function.

1
Expert's answer
2022-01-31T07:56:30-0500
# Python 3.9.5

# a)

def get_menu(stud_info, stud_id, stud_pin,n):
    if stud_info.get(stud_id) is not None and stud_info[stud_id] == stud_pin:
        print('You have access to the menu')
    else:
        print('Wrong login details')
        n += 1
        main(n)


def main(n):
    if n <= 2:
        stud_info = {12345: 1111}
        stud_id = int(input('Enter id: '))
        stud_pin = int(input('Enter pin: '))
        get_menu(stud_info, stud_id, stud_pin,n)
    else:
        print('You have exhausted your login attempts!')


if __name__ == '__main__':
    n = 1
    main(n)


# b)

def perimeter(a, b):
    perimeter = a + b + (a**2 + b**2)**(1/2)
    print(f'Perimeter: {perimeter}')


def area(a, b):
    area = a*b*(1 / 2)
    print(f'Area: {area}')


def main():
    a = int(input('Enter side a: '))
    b = int(input('Enter side b: '))
    perimeter(a, b)
    area(a, b)

if __name__ == '__main__':
    main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS