Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language is Python # Gift-assigner program import random numPeople = int(intput(How many people are playing? )) givers = [] recivers = [] print(Please enter their

Language is Python

# Gift-assigner program

import random

numPeople = int(intput("How many people are playing? "))

givers = []

recivers = []

print("Please enter their names: ")

# Get all of the players' names and add them to the list

for i in range(numPeople):

givers.append(input(""))

# Randomly assign gift givers to gift receivers. Check to make sure that nobody is assigned themselves (which is no fun!), and that each person can only give one gift and can only receive one gift (no repeats). Keep trying (looping) until everyone is giving a gift to someone else.

for j in range(numPeople):

recivers[j] = random.sample(givers, numPeople)

# Print results

print()

print("Gift Assignments...")

for k in range (numPeople):

print(givers[k], "will buy a gift for," recivers[k])

print()

Add to the starter code above to make sure that 1) nobody is assigned to buy a gift for themselves, and 2) each person can only give one gift and can only receive one gift (no repeats). Have the program keep trying (looping) until both of these conditions are met. The program should work every time regardless of the number of people participating.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions

Question

What was the key to solving this dilemma?

Answered: 1 week ago

Question

At what level(s) was this OD intervention scoped?

Answered: 1 week ago