python! no need for fancy code as simple as possible! The elders of Candyville have passed a by-law saying that all the children of the town must have a chance to gain some candy treats after school (but don’t worry...the candies are made with veggies and the children love them). The elders have placed candy vending machines all around the town for the children to access after school. To encourage sharing, there are some rules to be followed when a child uses one of these vending machines. Rule 1: The child must bring two friends with them to the vending machine and they must all have some candy already that they are willing to share if need be. They must each have an even number of candy to start with. Rule 2: The child must be wearing either red or blue or yellow shoes, and their two friends must be wearing one of the other colours of shoes, but all the children must all have different colour shoes on. Rule 3: The child must tell the vending machine their name, what colour shoes they have on, and how many candies they, and each of their friends, currently have. Rule 4: The vending machine will randomly generate a number representing a colour (1=red, 2=blue, or 3=yellow) and the vending machine will the display the actual colour name, rather than the number. Rule 5: The vending machine will dispense (display) a randomly generated even number of candies (an even number between 2 and 20, inclusive). Rule 6: If the random colour generated by the vending machine is the same colour as the child’s shoes, the child must divide their randomly generated and dispensed number of candies among their two friends, half to each. The child can retain all of their own candies that they had before they went to the vending machine. Rule 7: If the random colour generated by the vending machine is not the same colour as the shoes that the child is wearing, both friends must give the child half of their candy, and the child gets to keep the candy dispensed by the vending machine as well. Write a Python program to simulate the workings of this vending machine and report, at the end, how many candy and what percentage of candy the three children have, with appropriate labels. Note: • If the colour of the child’s shoes is entered as anything other than red, blue, or yellow, your program must output an error message. • If the current number of candies entered for either of the three children is not an even number or is non- positive for either of them, then your program must output an error message. • See textbook page 165 for an example of random number generation. For example, the input prompts, input (shown in bold blue) and corresponding output from the program could be as follows: Please enter your name: Charlie What is your shoe colour? (red/blue/yellow) blue How many candy do you have? (must be a positive even number) 56 How many candy does your first friend have? (must be a positive even number) 34 How many candy does your second friend have? (must be a positive even number) 20 Colour randomly generated is blue. Number of candy dispensed by the vending machine is 6. Total candy for Charlie is 56 which is 48.28%. Total candy for Charlie's first friend is 37 which is 31.90%. Total candy for Charlie's second friend is 23 which is 19.83%. Another example: Please enter your name: Bob What is your shoe colour? (red/blue/yellow) yellow How many candy do you have? (must be a positive even number) 55 How many candy does your first friend have? (must be a positive even number) -1 How many candy does your second friend have? (must be a positive even number) 22 Error: Number of candy incorrect! All must be even and 2 or more. Another example: Please enter your name: Lee What is your shoe colour? (red/blue/yellow) purple How many candy do you have? (must be a positive even number) 32 How many candy does your first friend have? (must be a positive even number) 18 How many candy does your second friend have? (must be a positive even number) 46 Error: Shoe colour incorrect! Must be red, blue, or yellow
python! no need for fancy code as simple as possible! The elders of Candyville have passed a by-law saying that all the children of the town must have a chance to gain some candy treats after school (but don’t worry...the candies are made with veggies and the children love them). The elders have placed candy vending machines all around the town for the children to access after school. To encourage sharing, there are some rules to be followed when a child uses one of these vending machines. Rule 1: The child must bring two friends with them to the vending machine and they must all have some candy already that they are willing to share if need be. They must each have an even number of candy to start with. Rule 2: The child must be wearing either red or blue or yellow shoes, and their two friends must be wearing one of the other colours of shoes, but all the children must all have different colour shoes on. Rule 3: The child must tell the vending machine their name, what colour shoes they have on, and how many candies they, and each of their friends, currently have. Rule 4: The vending machine will randomly generate a number representing a colour (1=red, 2=blue, or 3=yellow) and the vending machine will the display the actual colour name, rather than the number. Rule 5: The vending machine will dispense (display) a randomly generated even number of candies (an even number between 2 and 20, inclusive). Rule 6: If the random colour generated by the vending machine is the same colour as the child’s shoes, the child must divide their randomly generated and dispensed number of candies among their two friends, half to each. The child can retain all of their own candies that they had before they went to the vending machine. Rule 7: If the random colour generated by the vending machine is not the same colour as the shoes that the child is wearing, both friends must give the child half of their candy, and the child gets to keep the candy dispensed by the vending machine as well. Write a Python program to simulate the workings of this vending machine and report, at the end, how many candy and what percentage of candy the three children have, with appropriate labels. Note: • If the colour of the child’s shoes is entered as anything other than red, blue, or yellow, your program must output an error message. • If the current number of candies entered for either of the three children is not an even number or is non- positive for either of them, then your program must output an error message. • See textbook page 165 for an example of random number generation. For example, the input prompts, input (shown in bold blue) and corresponding output from the program could be as follows: Please enter your name: Charlie What is your shoe colour? (red/blue/yellow) blue How many candy do you have? (must be a positive even number) 56 How many candy does your first friend have? (must be a positive even number) 34 How many candy does your second friend have? (must be a positive even number) 20 Colour randomly generated is blue. Number of candy dispensed by the vending machine is 6. Total candy for Charlie is 56 which is 48.28%. Total candy for Charlie's first friend is 37 which is 31.90%. Total candy for Charlie's second friend is 23 which is 19.83%. Another example: Please enter your name: Bob What is your shoe colour? (red/blue/yellow) yellow How many candy do you have? (must be a positive even number) 55 How many candy does your first friend have? (must be a positive even number) -1 How many candy does your second friend have? (must be a positive even number) 22 Error: Number of candy incorrect! All must be even and 2 or more. Another example: Please enter your name: Lee What is your shoe colour? (red/blue/yellow) purple How many candy do you have? (must be a positive even number) 32 How many candy does your first friend have? (must be a positive even number) 18 How many candy does your second friend have? (must be a positive even number) 46 Error: Shoe colour incorrect! Must be red, blue, or yellow
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Topic Video
Question
In python! no need for fancy code as simple as possible!
The elders of Candyville have passed a by-law saying that all the children of the town must have a chance to
gain some candy treats after school (but don’t worry...the candies are made with veggies and the children love
them). The elders have placed candy vending machines all around the town for the children to access after
school. To encourage sharing, there are some rules to be followed when a child uses one of these vending
machines.
Rule 1: The child must bring two friends with them to the vending machine and they must all have some
candy already that they are willing to share if need be. They must each have an even number of candy to start
with.
Rule 2: The child must be wearing either red or blue or yellow shoes, and their two friends must be wearing
one of the other colours of shoes, but all the children must all have different colour shoes on.
Rule 3: The child must tell the vending machine their name, what colour shoes they have on, and how many
candies they, and each of their friends, currently have.
Rule 4: The vending machine will randomly generate a number representing a colour (1=red, 2=blue, or
3=yellow) and the vending machine will the display the actual colour name, rather than the number.
Rule 5: The vending machine will dispense (display) a randomly generated even number of candies (an even
number between 2 and 20, inclusive).
Rule 6: If the random colour generated by the vending machine is the same colour as the child’s shoes, the
child must divide their randomly generated and dispensed number of candies among their two friends, half to
each. The child can retain all of their own candies that they had before they went to the vending machine.
Rule 7: If the random colour generated by the vending machine is not the same colour as the shoes that the
child is wearing, both friends must give the child half of their candy, and the child gets to keep the candy
dispensed by the vending machine as well.
Write a Python program to simulate the workings of this vending machine and report, at the end, how many
candy and what percentage of candy the three children have, with appropriate labels.
Note:
• If the colour of the child’s shoes is entered as anything other than red, blue, or yellow, your program must
output an error message.
• If the current number of candies entered for either of the three children is not an even number or is non-
positive for either of them, then your program must output an error message.
• See textbook page 165 for an example of random number generation.
For example, the input prompts, input (shown in bold blue) and corresponding output from the program could
be as follows:
Please enter your name: Charlie
What is your shoe colour? (red/blue/yellow) blue
How many candy do you have? (must be a positive even number) 56
How many candy does your first friend have? (must be a positive even number)
34
How many candy does your second friend have? (must be a positive even number)
20
Colour randomly generated is blue.
Number of candy dispensed by the vending machine is 6.
Total candy for Charlie is 56 which is 48.28%.
Total candy for Charlie's first friend is 37 which is 31.90%.
Total candy for Charlie's second friend is 23 which is 19.83%.
gain some candy treats after school (but don’t worry...the candies are made with veggies and the children love
them). The elders have placed candy vending machines all around the town for the children to access after
school. To encourage sharing, there are some rules to be followed when a child uses one of these vending
machines.
Rule 1: The child must bring two friends with them to the vending machine and they must all have some
candy already that they are willing to share if need be. They must each have an even number of candy to start
with.
Rule 2: The child must be wearing either red or blue or yellow shoes, and their two friends must be wearing
one of the other colours of shoes, but all the children must all have different colour shoes on.
Rule 3: The child must tell the vending machine their name, what colour shoes they have on, and how many
candies they, and each of their friends, currently have.
Rule 4: The vending machine will randomly generate a number representing a colour (1=red, 2=blue, or
3=yellow) and the vending machine will the display the actual colour name, rather than the number.
Rule 5: The vending machine will dispense (display) a randomly generated even number of candies (an even
number between 2 and 20, inclusive).
Rule 6: If the random colour generated by the vending machine is the same colour as the child’s shoes, the
child must divide their randomly generated and dispensed number of candies among their two friends, half to
each. The child can retain all of their own candies that they had before they went to the vending machine.
Rule 7: If the random colour generated by the vending machine is not the same colour as the shoes that the
child is wearing, both friends must give the child half of their candy, and the child gets to keep the candy
dispensed by the vending machine as well.
Write a Python program to simulate the workings of this vending machine and report, at the end, how many
candy and what percentage of candy the three children have, with appropriate labels.
Note:
• If the colour of the child’s shoes is entered as anything other than red, blue, or yellow, your program must
output an error message.
• If the current number of candies entered for either of the three children is not an even number or is non-
positive for either of them, then your program must output an error message.
• See textbook page 165 for an example of random number generation.
For example, the input prompts, input (shown in bold blue) and corresponding output from the program could
be as follows:
Please enter your name: Charlie
What is your shoe colour? (red/blue/yellow) blue
How many candy do you have? (must be a positive even number) 56
How many candy does your first friend have? (must be a positive even number)
34
How many candy does your second friend have? (must be a positive even number)
20
Colour randomly generated is blue.
Number of candy dispensed by the vending machine is 6.
Total candy for Charlie is 56 which is 48.28%.
Total candy for Charlie's first friend is 37 which is 31.90%.
Total candy for Charlie's second friend is 23 which is 19.83%.
Another example:
Please enter your name: Bob
What is your shoe colour? (red/blue/yellow) yellow
How many candy do you have? (must be a positive even number) 55
How many candy does your first friend have? (must be a positive even number)
-1
How many candy does your second friend have? (must be a positive even number)
22
Error: Number of candy incorrect! All must be even and 2 or more.
Another example:
Please enter your name: Lee
What is your shoe colour? (red/blue/yellow) purple
How many candy do you have? (must be a positive even number) 32
How many candy does your first friend have? (must be a positive even number)
18
How many candy does your second friend have? (must be a positive even number)
46
Error: Shoe colour incorrect! Must be red, blue, or yellow.
Please enter your name: Bob
What is your shoe colour? (red/blue/yellow) yellow
How many candy do you have? (must be a positive even number) 55
How many candy does your first friend have? (must be a positive even number)
-1
How many candy does your second friend have? (must be a positive even number)
22
Error: Number of candy incorrect! All must be even and 2 or more.
Another example:
Please enter your name: Lee
What is your shoe colour? (red/blue/yellow) purple
How many candy do you have? (must be a positive even number) 32
How many candy does your first friend have? (must be a positive even number)
18
How many candy does your second friend have? (must be a positive even number)
46
Error: Shoe colour incorrect! Must be red, blue, or yellow.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 3 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY