Page 147 - CodePilot V5.0 C7
P. 147
Program 15 To print only odd numbers, skip any even number. Program 17 To know the amount of discount based on how much money you spent.
Amount spent Discount%
Program15.py
`5000 or more 20% off
File Edit Format Run Options Window Help
`3000 to `4999 10% off
for i in range(1, 11):
`1000 to `2999 5% off
if i % 2 == 0:
Less than `1000 No discount
continue # skip even numbers
print("Odd number:", i) Show the final amount of discount and amount to be paid.
print("Out of for loop")
Program17.py
File Edit Format Run Options Window Help
Output
amount = float(input("Enter the total purchase amount: "))
SHORT SIGN
Odd number: 1 if amount >= 5000:
Odd number: 3
Odd number: 5 To select all text: discount = 0.20 # 20% discount
Odd number: 7 print("You get a 20% discount.")
Ctrl + A
Odd number: 9
elif amount >= 3000:
Out of for loop
discount = 0.10 # 10% discount
print("You get a 10% discount.")
Ask elif amount >= 1000:
AGENT
OrangeAI
Write Python code to illustrate jump statements like break, continue and pass. discount = 0.05 # 5% discount
print("You get a 5% discount.")
Study
else:
discount = 0 # No discount
print("No discount available.")
SOME MORE PROGRAMS
discount_amount=amount*discount
Program 16 To find the average of the first 10 natural numbers. print("Discount amount is : ", discount_amount)
final_amount = amount - (amount * discount)
Program16.py
print("Amount to be paid after discount:", final_amount)
File Edit Format Run Options Window Help
total = 0
for i in range(1, 11):
Output
total += i
average = total / 10 Enter the total purchase amount: 2500
print("Average of first 10 natural numbers is:", average) You get a 5% discount.
Discount amount is: 125.0
Amount to be paid after discount: 2375.0
Output
Average of first 10 natural numbers is: 5.5
145
Flow of Control in Python

