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.
# 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()
Comments
Leave a comment