Who will pay the bill?
In London restaurants, it is not uncommon for a group of diners to pay the bill via card. To make it more fun, each of them bring the card and the restaurant server will pick one randomly and will pay the bill.
As a programmer, recreate this event through a python program. It will accept names separated by comma and space (“, “). Make a list out of the entered names and pick one randomly that will pay the bill.
Sample output:
Enter names: carlo,fedrick,jhon,icy
carlo will pay the bill
HINT:
1. Use split function
2. Use random module
3. Use len function
import random
while True:
names = input('enter names: ')
if len(names) == 0:
print('enter at least one name')
continue
else:
names = names.split(sep=', ')
index = random.randint(0,len(names)-1)
s = names[index] + ' will pay the bill'
print(s)
break
Comments
Leave a comment