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
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% 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
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
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy