Page 234 - Computer Science V2.0 Class 11
P. 234
Ans.
def login():
# Define the correct username and password
correctUid = "ADMIN"
correctPwd = "St0rE@1"
# Initialize the number of login attempts
attempts = 0
# Allow three attempts
while attempts < 3:
# Prompt the user for their credentials
uid = input("Enter user ID: ")
pwd = input("Enter password: ")
# Check if the entered credentials are correct
if uid == correctUid and pwd == correctPwd:
print("Login successful!")
break
else:
print("Invalid credentials. Please try again.")
attempts += 1
# If three wrong attempts are made, block the account
if attempts == 3:
print("Account blocked.")
# Example usage
login()
2. XYZ store plans to give festival discount to its customers. The store management has decided to give discount on the following criteria:
Shopping Amount Discount Offered
>=500 and <1000 5%
>=1000 and <2000 8%
>=2000 10%
An additional discount of 5% is given to customers who are the members of the store. Create a program using user defined function that
accepts the shopping amount as a parameter and calculates discount and net amount payable on the basis of the following conditions:
Net Payable Amount = Total Shopping Amount – Discount.
Ans.
def calculateDiscount(shoppingAmount, isMember):
# Define discount percentages based on shopping amount
if shoppingAmount >= 500 and shoppingAmount < 1000:
discountPercentage = 5
elif shoppingAmount >= 1000 and shoppingAmount < 2000:
discountPercentage = 8
elif shoppingAmount >= 2000:
discountPercentage = 10
220 Touchpad Computer Science (Ver. 2.0)-XI

