Advertisement
DJ8Target

Automate the Boring Stuff Comma Code

Feb 28th, 2021
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. spam=[]
  2. def comma_code(spam):
  3.     return 'spam[:-1]'+' and'+' spam[-1]'
  4. while True:
  5.     print('Please enter a list of at least two items.'+' (Or enter nothing to stop.):')
  6.     item=input()
  7.     if int(len(spam))< 2:
  8.         print('Your list is too short.')
  9.     if int(len(spam))>= 2:
  10.         print('You have entered a valid list.')
  11.     else:
  12.         break
  13.     spam=spam+ [item] # list concatenation
  14.  
  15. comma_code(spam)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement