I am trying to replicate this python code but I am unsure how to go about asking for a user inputted list one at a time and then how to present the list in order and then randomly. If anyone could point me in the right direction I would appreciate it
total = 0
while True:
List = input('Enter an item or "done" to stop entering items: ')
if List == 'done':
break
print(List)
This was my original idea but I don't think it makes any sense
CodePudding user response:
Append the input on an array:
all_values = []
while True:
value = input('Enter an item or "done" to stop entering items: ')
if value == 'done':
break
all_values.append(value)
print(all_values)
CodePudding user response:
import random
items = []
while True:
x = input('Enter an item or "done" to stop entering items: ')
if x == 'done':
break
items.append(x)
original = ' '.join(items)
print(f'Your items in original order: {original}')
random.shuffle(items)
shuffled = ' '.join(items)
print(f'Your items in random order: {shuffled}')