Python Classroom Series – 28/May/2021

range() function

  • The range function returns the sequence of number
  • Syntax:
range(start, stop, step)
start: optional, default is 0
stop: required
step: optional, default
  • Examples
range(6)
# we have passed stop = 6
# start => 0 (default)
# step => 1 (default)
0,1,2,3,4,5

Preview

Lets Write a python program which captures the items for shopping and number of items

  • We need to write a python program which accepts the following from the user
Enter the name of the item to be purchased: 
Enter the number of items to be purchases
Enter the price of the item
Do you want to continue [press y to continue or n to exit ] 
  • This program should have the two lists created
    • items
    • items_count
    • price
  • for the program Refer Here
  • Enter the following shopping data
item count price per unit
milk 10 30
eggs 24 6
bread 5 40
soda 10 40
  • Extend this program to print the purchased items as a Bill
QualityFresh

item   count    price per item    total price
milk    10         30               300
egg     24          6               144
bread   5           40              200
soda    10          40              400

total bill = 1044
  • Solution 1: using multiple lists Refer Here
  • Solution 2: using nested lists (list of lists) Refer Here
  • Exercise – 3: Give 10% discount if the bill is in the range of 500-10000 for anything above that give 15% discount

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin