Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% 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.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% 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.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

# 1.

Bike Road Tax and Final Amount


price = float(input("Enter cost price of bike: "))
if price > 100000:
tax = 0.15 * price
elif price > 50000:
tax = 0.10 * price
else:
tax = 0.05 * price
print("Road Tax:", tax)
print("Final Amount:", price + tax)

# 2. Square and Cube using Lambda


nums = [1, 2, 3, 4]
print("Squares:", list(map(lambda x: x**2, nums)))
print("Cubes:", list(map(lambda x: x**3, nums)))

# 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()

# ... (content continues until #38)

You might also like