Answer to Question #183252 in Python for Angelie Suarez

Question #183252

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


1
Expert's answer
2021-04-24T11:32:15-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS