Sale!

# CENG113 HOMEWORK  4 Programming Basics Solved

\$35.00

Category:

## Description

5/5 - (1 vote)

You are expected to write a Python program for Santa Claus to help him distribute the gifts that the
children all around the world ask for. Santa Claus is living in his house with his elves in the North
Pole, where he keeps unlimited source of toys in his workshop to grant the children’s wishes.
In our scenario, there are 2 villages, 8 houses and 15 children, each of them with a wish for Christmas
from Santa.

Some of the children live in the same house and some of the houses are in the same
village. In Figure 1, you can see the map of the world for our program. Under every house, its
coordinates (x,y) are written.
Figure 1: The map of the world

There are 3 types of items that children can wish for, and each item has different volumes: stuffed
toy: 7 units, train: 5 units and doll: 3 units. Below, each children living in each house is listed with
his/her name and wish:
Name Wish
House1
Sophia Doll
Ethan Train
Liam Stuffed Toy
House2 Zoe Doll
Emma Doll
House3 Emily Doll
William Stuffed Toy
House4 Olivia Train
Jack Stuffed Toy
House5

Hannah Doll
Benjamin Train
Michael Stuffed Toy
House6 Sarah Stuffed Toy
House7 Owen Train
House8 Max Stuffed Toy

Santa’s sleigh can take maximum 15 units of items and can only make 8.000 kilometers until
Christmas Eve. The user has to help Santa to distribute the toys before the total distance travelled
exceeds that limit.
Your program should have 4 classes named as Santa, Item, Child and Sleigh.
● Santa has a sleigh, a list of children, remaining distance and the (x,y) coordinates of his current
location.
● Item has a type and the corresponding volume.
● Sleigh has a capacity of 15 unit and a list of current items it holds.
● Child has a name, a wish item and an (x,y) coordinate of his/her house.
You should create instances of each class in your main program. For example,
wish1 = Item(“Doll”)
child1 = Child(“Sophia”,wish1,(150,495))

The day before Christmas Eve, Santa asks one of his elves to collect the wishes of the children. For
this purpose, you have to implement collect_wishes(world_list) function in a recursive manner
inside the Santa class that takes the list of our world as shown below:
world_list = [[[(“Sophia”, (150,495), “Doll”), (“Ethan”, (150,495), “Train”),
(“Liam”, (150,495), “Stuffed Toy”)], [(“Zoe”, (220,400), “Doll”), (“Emma”,
(220,400), “Doll”)], [(“Emily”, (300,465), “Doll”)), (“William”, (300,465), “Stuffed
Toy”)]], [[(“Olivia”, (490,380), “Train”), (“Jack”, (490,380), “Stuffed Toy”)],
[(“Hannah”, (590,400), “Doll”), (“Benjamin”, (590,400), “Train”), (“Michael”,
(590,400), “Stuffed Toy”)], [(“Sarah”, (530,490), “Stuffed Toy”)]], [(“Owen”,
(310,690), “Train”)], [(“Max”, (610,620), “Stuffed Toy”)]]
and it returns the list of all child instances like shown below:
[child1, child2, child3, child4, child5, child6, child7, child8, child9, child10,
child11, child12, child13, child14, child15]

At the beginning, the sleigh has 1 Stuffed Toy, 1 Doll and 1 Train. After collecting the wishes, the
program should start by showing the distance of each child from Santa’s Workshop (Santa’s current
location). You should calculate the distances by using the following formula (You should convert each
distance to integer by using int()):
D = √(x ) 2 − x1
2 + (y ) 2 − y1
2
Then, the program should ask the user to which child Santa has to go next. Before going to the given
destination, the program first checks whether the sleigh includes that child’s wish. If not, the program
should call load_cargo() function that asks the user which toys and how many of them will be
loaded. (load_cargo() function can be called in only Santa’s workshop. Otherwise, Santa has to return
to his workshop in order to load the cargo.)

After giving the child’s wish, the program should remove that child from the wish list. The program
should also update the current location of Santa and the remaining distance after every move.
At each turn, the program should display the remaining children and their distances from Santa’s
current location, and ask for Santa’s next move.
The program finishes when there is no child left, or the total distance travelled exceeds 8.000
kilometers.

## IMPORTANT NOTES:

● User inputs are case insensitive.
● Be careful about invalid inputs! Ask each question over and over again until a valid input is
entered.

## Submission Rules:

STUDENTS WHO DO NOT FOLLOW THESE RULES WILL BE GRADED AS 0.
1. You should submit your assignments through CMS until due date.
2. Your homework should be named as CENG113_hw4_studentID.py (ie:
CENG113_hw4_123456789).
3. Use comments in your code, otherwise you will lose some points.
4. Write your student ID as a comment at the beginning of your code.
Note: Violation of any submission rule may end up with point deduction up to 100 points. Any kind of
cheating including teamwork will be penalized.

An example scenario for the given world (user inputs are given in bold):
Welcome to Santa Claus’ Workshop!
Remaining Distance 8.000 kilometers.
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| Sophia | 517 km | Doll |
| Ethan | 517 km | Train |
| Liam | 517 km | Stuffed Toy |
| Zoe | 456 km | Doll |
| Emma | 456 km | Doll |
| Emily | 553 km | Doll |
| William | 553 km | Stuffed Toy |
| Olivia | 620 km | Train |
| Jack | 620 km | Stuffed Toy |
| Hannah | 712 km | Doll |
| Benjamin | 712 km | Train |
| Micheal | 712 km | Stuffed Toy |
| Sarah | 721 km | Stuffed Toy |
| Owen | 756 km | Train |
| Max | 869 km | Stuffed Toy |
————————————-

Santa’s sleigh has: 1 Doll, 1 Train, 1 Stuffed Toy
Where should Santa go next? Sophia
Checking Cargo!
Santa is going to Sophia!
Remaining Distance: 7483 km.
Here are the children left that needs their Christmas presents and their distance
from Santa:
————————————-
| name | distance | wish |
————————————-
| Ethan | 0 km | Train |
| Liam | 0 km | Stuffed Toy |
| Zoe | 118 km | Doll |
| Emma | 118 km | Doll |
| Emily | 152 km | Doll |
| William | 152 km | Stuffed Toy |
| Olivia | 358 km | Train |
| Jack | 358 km | Stuffed Toy |
| Hannah | 450 km | Doll |
| Benjamin | 450 km | Train |
| Michael | 450 km | Stuffed Toy |
| Sarah | 380 km | Stuffed Toy |
| Owen | 252 km | Train |
| Max | 476 km | Stuffed Toy |
————————————-

Santa’s sleigh has: 0 Doll, 1 Train, 1 Stuffed Toy
Where should Santa go next? Etha
There is no child named Etha!!!
Where should Santa go next? Ethan
Checking Cargo!
Santa is going to Ethan!
Remaining Distance: 7483 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-

| Liam | 0 km | Stuffed Toy |
| Zoe | 118 km | Doll |
| Emma | 118 km | Doll |
| Emily | 152 km | Doll |
| William | 152 km | Stuffed Toy |
| Olivia | 358 km | Train |
| Jack | 358 km | Stuffed Toy |
| Hannah | 450 km | Doll |
| Benjamin | 450 km | Train |
| Michael | 450 km | Stuffed Toy |
| Sarah | 380 km | Stuffed Toy |
| Owen | 252 km | Train |
| Max | 476 km | Stuffed Toy |
————————————-
Santa’s sleigh has: 0 Doll, 0 Train, 1 Stuffed Toy
Where should Santa go next? Liam
Checking Cargo!
Santa is going to Liam!
Remaining Distance: 7483 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-

| name | distance | wish |
————————————-
| Zoe | 118 km | Doll |
| Emma | 118 km | Doll |
| Emily | 152 km | Doll |
| William | 152 km | Stuffed Toy |
| Olivia | 358 km | Train |
| Jack | 358 km | Stuffed Toy |
| Hannah | 450 km | Doll |
| Benjamin | 450 km | Train |
| Michael | 450 km | Stuffed Toy |
| Sarah | 380 km | Stuffed Toy |
| Owen | 252 km | Train |
| Max | 476 km | Stuffed Toy |
————————————-

Santa’s sleigh has: 0 Doll, 0 Train, 0 Stuffed Toy
Where should Santa go next? Zoe
Checking Cargo!
Santa is going to Workshop to load cargo!
Would you like to add an item (Enter y/n): y
The items are added to Santa’s sleigh.
Would you like to add an item (Enter y/n): y
The items are added to Santa’s sleigh.
Would you like to add an item (Enter y/n): y
Please enter your desired item name and number seperated with comma:Stuffed Toy,1
The total size of items that you entered exceeds the capacity of the sleigh!
Would you like to add an item (Enter y/n): n
Santa is going to Zoe!
Remaining Distance: 6510 km

Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| Emma | 0 km | Doll |
| Emily | 103 km | Doll |
| William | 103 km | Stuffed Toy |
| Olivia | 270 km | Train |
| Jack | 270 km | Stuffed Toy |
| Hannah | 370 km | Doll |
| Benjamin | 370 km | Train |
| Michael | 370 km | Stuffed Toy |
| Sarah | 322 km | Stuffed Toy |
| Owen | 303 km | Train |
| Max | 447 km | Stuffed Toy |
————————————-
Santa’s sleigh: 1 Doll, 1 Train, 0 Stuffed Toy
Where should Santa go next? Emma
Checking Cargo!
Santa is going to Emma!
Remaining Distance: 6510 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-

| Emily | 103 km | Doll |
| William | 103 km | Stuffed Toy |
| Olivia | 270 km | Train |
| Jack | 270 km | Stuffed Toy |
| Hannah | 370 km | Doll |
| Benjamin | 370 km | Train |
| Michael | 370 km | Stuffed Toy |
| Sarah | 322 km | Stuffed Toy |
| Owen | 303 km | Train |
| Max | 447 km | Stuffed Toy |
————————————-
Santa’s sleigh: 0 Doll, 1 Train, 0 Stuffed Toy
Where should Santa go next? Olivia
Checking Cargo!
Santa is going to Olivia!
Remaining Distance: 6240 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-

| Emily | 208 km | Doll |
| William | 208 km | Stuffed Toy |
| Jack | 0 km | Stuffed Toy |
| Hannah | 101 km | Doll |
| Benjamin | 101 km | Train |
| Michael | 101 km | Stuffed Toy |
| Sarah | 117 km | Stuffed Toy |
| Owen | 358 km | Train |
| Max | 268 km | Stuffed Toy |
————————————-
Santa’s sleigh: 0 Doll, 0 Train, 0 Stuffed Toy
Where should Santa go next? Emily
Checking Cargo!
Santa is going to Workshop to load cargo!
Would you like to add an item (Enter y/n): y
Please enter your desired item name and number seperated with comma:Stuffed Toy,2
Would you like to add an item (Enter y/n): n
Santa Claus didn’t go to Emily
Where should Santa go next?: Sarah
Checking Cargo!
Santa is going to Sarah!
Remaining Distance: 4899 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-

| Emily | 231 km | Doll |
| William | 231 km | Stuffed Toy |
| Jack | 117 km | Stuffed Toy |
| Hannah | 108 km | Doll |
| Benjamin | 108 km | Train |
| Michael | 108 km | Stuffed Toy |
| Owen | 297 km | Train |
| Max | 152 km | Stuffed Toy |
————————————-
Santa’s sleigh: 0 Doll, 0 Train, 1 Stuffed Toy
Where should Santa go next? Max
Checking Cargo!
Santa is going to Max!
Remaining Distance: 4747 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| Emily | 346 km | Doll |
| William | 346 km | Stuffed Toy |
| Jack | 268 km | Stuffed Toy |
| Hannah | 220 km | Doll |
| Benjamin | 220 km | Train |
| Michael | 220 km | Stuffed Toy |
| Owen | 308 km | Train |
————————————-
Santa’s sleigh has: 0 Doll, 0 Train, 0 Stuffed Toy
Where should Santa go next?: Hannah
Checking Cargo!
Santa is going to Workshop to load cargo!
Would you like to add an item (Enter y/n): y
Would you like to add an item (Enter y/n): y
Would you like to add an item (Enter y/n): y
Please enter your desired item name and number seperated with comma:Stuffed Toy,1
Would you like to add an item (Enter y/n): n
Santa is going to Hannah!
Remaining Distance: 3166 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| Emily | 297 km | Doll |
| William | 297 km | Stuffed Toy |
| Jack | 101 km | Stuffed Toy |
| Benjamin | 0 km | Train |
| Michael | 0 km | Stuffed Toy |
| Owen | 403 km | Train |
————————————-
Santa’s sleigh has: 0 Doll, 1 Train, 1 Stuffed Toy
Where should Santa go next?:Benjamin
Checking Cargo!
Santa is going to Benjamin!
Remaining Distance: 3166 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| Emily | 297 km | Doll |
| William | 297 km | Stuffed Toy |
| Jack | 101 km | Stuffed Toy |
| Michael | 0 km | Stuffed Toy |
| Owen | 403 km | Train |
————————————-
Santa’s sleigh has: 0 Doll, 0 Train, 1 Stuffed Toy
Where should Santa go next?: Michael
Checking Cargo!
Santa is going to Michael!
Remaining Distance: 3166 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| Emily | 297 km | Doll |
| William | 297 km | Stuffed Toy |
| Jack | 101 km | Stuffed Toy |
| Owen | 403 km | Train |
————————————-
Santa’s sleigh has: 0 Doll, 0 Train, 0 Stuffed Toy
Where should Santa go next?:Emily
Checking Cargo!
Santa is going to Workshop to load cargo!
Would you like to add an item (Enter y/n): y
Would you like to add an item (Enter y/n): y
Please enter your desired item name and number seperated with comma:Stuffed Toy,1
Would you like to add an item (Enter y/n): n
Santa is going to Emily!
Remaining Distance: 1901 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| William | 0 km | Stuffed Toy |
| Jack | 208 km | Stuffed Toy |
| Owen | 225 km | Train |
————————————-
Santa’s sleigh has: 0 Doll, 0 Train, 1 Stuffed Toy
Where should Santa go next?: William
Checking Cargo!
Santa is going to William!
Remaining Distance: 1901 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| Jack | 208 km | Stuffed Toy |
| Owen | 225 km | Train |
————————————-
Santa’s sleigh has: 0 Doll, 0 Train, 0 Stuffed Toy
Where should Santa go next?: Jack
Checking Cargo!
Santa is going to Workshop to load cargo!
Would you like to add an item (Enter y/n): y
Would you like to add an item (Enter y/n): y
Please enter your desired item name and number seperated with comma:stuffed toy,1
Would you like to add an item (Enter y/n): n
Santa is going to Jack!
Remaining Distance: 728 km
Here are the children left that need their Christmas presents and their distances
from Santa:
————————————-
| name | distance | wish |
————————————-
| Owen | 358 km | Train |
————————————-
Santa’s sleigh has: 0 Doll, 1 Train, 0 Stuffed Toy
Where should Santa go next?: Owen
Checking Cargo!
Santa is going to Owen!
Congratulations!!! You managed to help Santa.