Page 306 - Touhpad Ai
P. 306
amount_to_be_paid = total_cost - discount
# Display the discount, amount to be paid, and the assured gift with two decimal
places
print(f"Discount: Rs {discount:.2f}")
print(f"Amount to be paid: Rs {amount_to_be_paid:.2f}")
print(f"Assured Gift: {gift}")
Output:
Enter the total cost of the items purchased (in Rs): 5168.50
Discount: Rs 775.27
Amount to be paid: Rs 4393.23
Assured Gift: Electric Iron
15. Write a program that calculates the sum of numbers entered by the user. The loop should continue as long as the
user does not enter a negative number. The loop will exit when a negative number is entered. Display the sum of the
entered numbers.
# Initialize the sum to 0
total_sum = 0
print("Enter numbers to add to the sum. Enter a negative number to stop.")
while True:
# Accept a number from the user
number = int(input("Enter a number: "))
# Check if the number is negative
if number < 0:
break # Exit the loop if a negative number is entered
# Add the number to the total sum
total_sum += number
# Display the total sum
print("The total sum of the entered numbers is:",total_sum)
Output:
Enter numbers to add to the sum. Enter a negative number to stop.
Enter a number: 5
Enter a number: 3
Enter a number: 12
Enter a number: 23
Enter a number: -7
The total sum of the entered numbers is: 43
16. Create a dictionary which will store names of Indian cities and their respective population. Display the data of the
dictionary.
cities = {
"Mumbai": 12442373,
"Delhi": 11034555,
"Bangalore": 8443675,
"Hyderabad": 6993262,
"Chennai": 4646732
}
for city, population in cities.items():
print("City:", city, " It's Population:",population)
304 Touchpad Artificial Intelligence - XI

