Advertisement
M_Asif_Khan

Using Counter

Feb 25th, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. shopping = ["bread","cheese", "apple","tomato","biscuits"]
  2. count = 0
  3. ## by using a counter
  4. for item in shopping:
  5. print(item)
  6. count = count + 1
  7. countString = str(count)
  8.  
  9. print("You have "+ countString + " items in your shopping list.")
  10.  
  11. ## by using str.len(object)
  12. print("You have "+str(len(shopping))+" items in your shopping list.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement