elena_gancedo

Create list and show it

Jun 26th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. shopping = [] # Let's create an empty list variable
  2. how_many = input("How many items of shopping are needed? ")
  3. how_many = int(how_many)
  4. for item_number in range(how_many): # Let's add a "for" loop with a range to loop x times
  5.     item = input("What is item number " + str(item_number) + "? ") #
  6.     shopping.append(item) # Let's append item to the list
  7. print(shopping) # After the "for" loop let’s print the list
  8. for item in shopping:
  9.     print(item)
  10. len(shopping)
  11. result = str(len(shopping))# Function "len"
  12. print ("I have " + result + " items in my shopping account") # Let's show a total at the end
  13.  # Another way to show a total at the end
  14. print "The items in my shopping account are",len (shopping)
  15. count = 0
  16. for item in shopping:
  17.     print(item)
  18.     count = count + 1 # Counter
  19.     print(count)
Add Comment
Please, Sign In to add comment