The document contains Python code snippets for three different functionalities: calculating bike road tax based on price, generating squares and cubes of a list of numbers using lambda functions, and implementing a menu-driven calculator with exception handling. Each section provides a clear implementation of the respective functionality. The code is structured to handle user input and perform calculations accordingly.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views
Python_Programs_Collection
The document contains Python code snippets for three different functionalities: calculating bike road tax based on price, generating squares and cubes of a list of numbers using lambda functions, and implementing a menu-driven calculator with exception handling. Each section provides a clear implementation of the respective functionality. The code is structured to handle user input and perform calculations accordingly.
# 3. Menu-driven Calculator with Exception Handling
def calculator(): while True: print("\n1.Add 2.Subtract 3.Multiply 4.Divide 5.Exit") try: ch = int(input("Choice: ")) if ch == 5: break a = float(input("A: ")) b = float(input("B: ")) if ch == 1: print("Sum:", a + b) elif ch == 2: print("Diff:", a - b) elif ch == 3: print("Product:", a * b) elif ch == 4: print("Quotient:", a / b) else: print("Invalid Choice") except Exception as e: print("Error:", e) calculator()