Data Management In Programming - Need Tips.

Captaintj

Regular Member
Joined
Dec 28, 2018
Messages
307
Reaction score
208
So guys I have been doing this book - Automate boring stuff with Python.

After finishing the Chapter 4, there came 2 project questions that went completely over my head. I am not able to solve these problems related to lists.

I need to learn Data Management ,handling and showing it in graphs and stuff for my dads work.

Would you guys recommend any Data course in Udemy or any other website to learn such stuff?
#**************************
Btw the questions I didn't understand were these 2 below. It has really but my morale down and I feel I am not good enough to learn coding because I should be able to answer these questions or maybe the book people give a tough questions for us to improve or idk. Feeling low because of this, maybe this is what it means to be a programmer, to learn to solve problems that are tough to solve?

1) Comma Code
Say you have a list value like this:
spam = ['apples', 'bananas', 'tofu', 'cats']
Write a function that takes a list value as an argument and returns a
string with all the items separated by a comma and a space, with and
inserted before the last item. For example, passing the previous spam list to
the function would return 'apples, bananas, tofu, and cats'. But your
function should be able to work with any list value passed to it. Be sure to
test the case where an empty list [] is passed to your function.

2)
Coin Flip Streaks
For this exercise, we’ll try doing an experiment. If you flip a coin 100
times and write down an “H” for each heads and “T” for each tails, you’ll
create a list that looks like “T T T T H H H H T T.” If you ask a human
to make up 100 random coin flips, you’ll probably end up with alternating
head-tail results like “H T H T H H T H T T,” which looks random (to
humans), 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 heads 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 loop 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 random.randint(0, 1) will return a 0 value 50% of the time and a
1 value the other 50% of the time.
You can start with the following template:
import random
numberOfStreaks = 0
for experimentNumber 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: %s%%' % (numberOfStreaks / 100))
 
1)
def comma_function(list):
output = ''
for i in list:
output = output + i + ','
return output

This should work I think, didn't test it. Just typed it on my mobile
 
You can use join for the first.

Code:
def comma(words):
    return ", ".join(words)

upload_2020-6-11_9-27-45.png
 
Some articles and courses about python data structures and algorithms:

https://www.edureka.co/blog/data-structures-in-python/

https://www.tutorialspoint.com/python_data_structure/index.htm

https://www.udacity.com/course/data-structures-and-algorithms-in-python--ud513
 
Back
Top