Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. Directions Using the following guidelines, create a python program. 1. Create a program named commaCode.py. 2. Add three comment lines at the top of

image text in transcribedimage text in transcribed

3. Directions Using the following guidelines, create a python program. 1. Create a program named commaCode.py. 2. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) Write a commaCode function as described in a section named Comma Code on page 102 (107 in the 2nd Edition). 4. In your program, create four lists as follows: animalList1 = ['dog', 'cat', 'bird', 'tiger', 'lion', 'camel'] animalList2 = ['elephant', 'alligator'] animalList3 = ['horse'] animalList4 = 0 5. When you run your program, pass each list to the commaCode() function and then print out the result as shown in the Example Output. 6. Submit the commaCode.py file into the Chapter 4 Assignment 3 Submission Folder. Hints 1. Ensure to account for lists that are empty (should return an empty string), contain one item (should simply return that item), and contain two items (should return the two items separated by 'and"). Example Output Le Python 3.8.1 Shell File Edit Shell Debug Options Window Help Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) (MSC v.1916 64 bi t (AMD64)] on win32 Type "help", "copyright", "credits" or "license ()" for more information. >>> = RESTART: G:\TTC_Courses\cpt180\CPT180 Version 2\Assignments\Python Soluti ons commaCode.PY animalListl - dog, cat, bird, tiger, lion, and camel animalList2 elephant and alligator animalList3 horse animal List >>>| up 100 random coin flips, you'll probably end up with alternating head tail resulte lika "HTHTHHTHTT," whick lock random (ta humana). but isn't mathematically random. A human will almost never write down a streak of six heads or six tails in a row, even though it is highly likely to happen in truly random coin flips. Humans are predictably bad at being random Write a program to find out how often a streak of six heacts or a streak of six tails comes up in a randomly generated list of heads and tails. Your program breaks up the experiment into two parts: the first part generates a list of randomly selected "heads and tails' values, and the second part checks if there is a streak in it. Put all of this code in a kop that repeats the experiment 10,000 times so we can find out what percentage of the coin flips contains a streak of six heads or tails in a row. As a hint, the function call randon.randint(0, 1) will return a o value 50% of the time and a 1 value the other 50% of the time. You can start with the following template: import randon numberOfStreaks - 0 for experiment Number in range(10000): # Code that creates a list of 100 "heads" or "tails' values. # Code that checks if there is a streak of 6 heads or tails in a row. print("Chance of streak: XXX X (numberOfStreaks / 100)) Of course, this is only an estimate, but 10,000 is a decent sample size. Some knowledge of mathematics could give you the exact answer and save you the trouble of writing a program, but programmers are notoricusly bad at math Character Picture Grid Say you have a list of lists where each value in the inner lists is a one-character string like this: grid - Il'., t'. 'O', 'o', t'o', 'o', 'o', '0', ['0', 'o', 'o', 'O, 0 [.', o', 'o', '0', ['o', '0', 'a', '0', ( 'o', 'o', 'o', 'O 'o', 'O Think of grid[x][y] as being the character at the x- and y-coordinates of a "picture" drawn with text characters. The (0, 0) origin is in the upper left corner, the x-coordinates increase going right, and the y coordinates increase going down. Chaped Copy the previous grid value, and write code that uses it to print the image ..00.00.. .0000000 .0000000. ..00000.. ...000... ..0.... Hint: You will need to use a loop in a loop in order to print gridto. then grid[1][, then grid[2][0), and so on, up to grid[8][0]. This will fin- ish the first row, so then print a newline. Then your program should print grid[0][1], then grid[1][1], then grid[2][:), and so on. The last thing your program will print is grid[8[). Also, remember to pass the end keyword argument to print() if you don't want a newline printed automatically after each print() call

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

8. Managers are not trained to be innovation leaders.

Answered: 1 week ago