Advertisement
HBSB

3.7 shopping_list and count

Mar 4th, 2020
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. count=0
  2. shopping=["bread", "cheese", "apple", "tomato", "biscuits" ]
  3. for item in shopping:
  4.   count=count+1
  5.   print (item)
  6. print("You have " + str(count) + " items in your shopping list")  
  7. #so I've not told it how many times to run, it just runs the complete list
  8. #each item is printed and then the program stops
  9.  
  10. #now we will count the items on the list and print the total at the end of the program.
  11. #at the top of the program, create a variable called count and set to zero
  12.  
  13. #then add the extended print line, NOT indented AND NOT forgetting that count has to be
  14. #converted into a string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement