Python For Everybody (All the Solved Exercises - Coursera & edX Full Course)

preview_player
Показать описание

Follow me on

In this video I am putting together all the exercises from the book "Python for Everybody", which Dr. Chuck offers for free here:
Here is the code for the solutions:

Here is the missing exercise 5 from chapter 12:

Make sure to check out my other tutorial series on Django:

Chapters:
00:00 Introduction
01:14 Chapter 2 - Exercise 2
05:24 Chapter 2 - Exercise 3
11:03 Chapter 2 - Exercise 5
14:12 Chapter 3 - Exercise 1
17:56 Chapter 3 - Exercise 2
20:36 Chapter 3 - Exercise 3
27:21 Chapter 4 - Exercise 6
31:37 Chapter 4 - Exercise 7
20:36 Chapter 5 - Exercise 1
43:35 Chapter 5 - Exercise 2
48:30 Chapter 6 - Exercise 5
53:27 Chapter 7 - Exercise 1
58:01 Chapter 7 - Exercise 2
1:06:55 Chapter 7 - Exercise 3
1:10:00 Chapter 8 - Exercise 4
1:16:35 Chapter 8 - Exercise 5
1:23:35 Chapter 8 - Exercise 6
1:27:40 Chapter 9 - Exercise 2
1:36:20 Chapter 9 - Exercise 3
1:39:51 Chapter 9 - Exercise 4
1:46:34 Chapter 9 - Exercise 5
1:51:58 Chapter 10 - Exercise 1
1:58:42 Chapter 10 - Exercise 2
2:09:07 Chapter 10 - Exercise 3
2:19:14 Chapter 11 - Exercise 1
2:26:09 Chapter 11 - Exercise 2
2:32:40 Chapter 12 - Exercise 1
2:39:57 Chapter 12 - Exercise 2
2:44:15 Chapter 12 - Exercise 3
2:48:26 Chapter 12 - Exercise 4
2:53:15 Chapter 13 - Exercise 1
Рекомендации по теме
Комментарии
Автор

Timestamps

00:00 Introduction
01:14 Chapter 2 - Exercise 2
05:24 Chapter 2 - Exercise 3
11:03 Chapter 2 - Exercise 5
14:12 Chapter 3 - Exercise 1
17:56 Chapter 3 - Exercise 2
20:36 Chapter 3 - Exercise 3
27:21 Chapter 4 - Exercise 6
31:37 Chapter 4 - Exercise 7
20:36 Chapter 5 - Exercise 1
43:35 Chapter 5 - Exercise 2
48:30 Chapter 6 - Exercise 5
53:27 Chapter 7 - Exercise 1
58:01 Chapter 7 - Exercise 2
1:06:55 Chapter 7 - Exercise 3
1:10:00 Chapter 8 - Exercise 4
1:16:35 Chapter 8 - Exercise 5
1:23:35 Chapter 8 - Exercise 6
1:27:40 Chapter 9 - Exercise 2
1:36:20 Chapter 9 - Exercise 3
1:39:51 Chapter 9 - Exercise 4
1:46:34 Chapter 9 - Exercise 5
1:51:58 Chapter 10 - Exercise 1
1:58:42 Chapter 10 - Exercise 2
2:09:07 Chapter 10 - Exercise 3
2:19:14 Chapter 11 - Exercise 1
2:26:09 Chapter 11 - Exercise 2
2:32:40 Chapter 12 - Exercise 1
2:39:57 Chapter 12 - Exercise 2
2:44:15 Chapter 12 - Exercise 3
2:48:26 Chapter 12 - Exercise 4
2:53:15 Chapter 13 - Exercise 1

aksonai
Автор

My answer for exercise 5.9_2. It is closer to the book's syntax:

smallest = None
largest = None

while True:
line = input("please enter a number or done")
if line == "done" :
break

try:
val = float(line)
except:
print("please enter a valid number or done")
continue


if smallest == None or val < smallest:
smallest = val
elif largest == None or val > largest:
largest = val

print(smallest, largest)

TheCrusaderRabbits
Автор

I can't tell how great it is when recommendation knows me I NEED music playlist when I'm coding.But what could makes it even better---the one who uploaded the coding music playlist actually knows
Thank you.

astrid
Автор

Started this course a few weeks ago. This is gonna be super helpful. Thanks for this

Danmaster
Автор

For chapter 8, exercise 4: I understood that the sorted list should contain only words that appear ONCE in the rome.txt since they are referred as "unique words". So to my understandinf, words like "is", "sun" should not be in the printed list since they occur more than once in the text. Thank you.

eo
Автор

hey man, you just helped so many beginners i really wanna say thanks alot mate and keep it up, subscribed, u are such a legend

pastalino
Автор

My Solution for Ex.7.3
# create a egg.txt file and save it in same folder as the mbox ones.
# I think author wants us to open a egg.txt file.

fname = input("Enter the file name: ")
if fname == "na na boo boo":
egg = open("egg.txt")
egg = egg.read()
print(egg)
quit()

try:
fhand = open(fname)
except:
print("The name you entered is wrong:", fname)
quit()

count = 0
total = 0
for line in fhand:

if line.find ("X-DSPAM-Confidence:") == - 1:
continue

else:

atpos = line.find(":")
numpos = line[atpos+1:]
total = total + float(numpos)
count = count + 1
print("The spam confidence is: ", total/count)

TheCrusaderRabbits
Автор

My answer for 9.2. It works, but aksonai's is better:

inputed = input("What is the file?")

try:
fhandl = open(inputed)
except:
print("Is that name correct?")
exit()

ddictionary = dict()

for line in fhandl:
line = line.rstrip()
if not line.startswith("From "):
continue
date = line.split()[2]
#date = words[2]
if date not in ddictionary:
ddictionary[date] = 1
else:
ddictionary[date] += 1
print(ddictionary)

TheCrusaderRabbits
Автор

My Solution for chapter 7. exercise 2:

fname = input("Enter the file name: ")
fhand = open(fname)
count = 0
total = 0
for line in fhand:

if line.find ("X-DSPAM-Confidence:") == - 1:
continue

else:

atpos = line.find(":")
numpos = line[atpos+1:]
print (count)
print(numpos)
total = total + float(numpos)
count = count + 1
print("The spam confidence is: ", total/count)

TheCrusaderRabbits
Автор

ty so much for doing these videos!!! Also, your lofi mixes are great, keep it up!

romeurodrigues
Автор

Ex, 4_6 31:38. It isn't necessary to move the two inputs below the function. They could stay above it. So why move it? We should define our variables before we use them.

TheCrusaderRabbits
Автор

This is so helpful. Thank you so much. This is a perfect companion to the course!

dcd
Автор

My answer for chapter 9:Dictionaries. I used find, which we learned earlier. I did not use split.

fhandl = open("mbox-short.txt")

dictionary = dict()

for line in fhandl:
line = line.rstrip()
if not line.startswith("From "):
continue

atpos = line.find("@")
sppos = line.find(' ', atpos)

domain_name = line[atpos+1:sppos]
print(domain_name)

dictionary[domain_name] = dictionary.get(domain_name, 0) + 1

TheCrusaderRabbits
Автор

I solved Chapter 5 exercise 2 by using a funktion

def function(user, maximum, minimum):

while user != "done":
user = (input("Enter a number: "))
if user == "done":
break
if int(user) > maximum:
maximum = int(user)
elif int(user) < maximum:
minimum = int(user)

print(maximum)
print(minimum)

function((input("Enter a number: ")), 0, 0)

faker_fakerplaymaker
Автор

I was getting really annoyed with the ".0" being left at the end of the whole numbers. For Chapter 2 Exercise 5. So I pieced together information from a couple different tutorials and figured out how to fix it.

celsius = input("What is the temperature Celsius?\n")

if '.' in celsius:
celsius = float(celsius)
decimals = 2
else:
celsius = int(celsius)
decimals = 0

fahrenheit = (celsius * 1.8 + 32)

print("The temperature in Fahrenheit is: {0:.{1}f}" .format(fahrenheit, decimals))

I will start working on the next chapter tomorrow. I am glad I found this video and downloaded the book.

JoshB.Podcast
Автор

chap4ex7
def computegrade(score):
try:
fscore = float(score)
if fscore < 0.0 or fscore > 1.0:
raise ValueError
except:
return 'bad score'
if fscore >= 0.9:
return 'A'
elif fscore >= 0.8:
return 'B'
elif fscore >= 0.7:
return 'C'
elif fscore >= 0.6:
return 'D'
else:
return 'F'




while True:
score = input('> ')
if score == 'done':
break
else:
print(computegrade(score))

samucancld
Автор

Thanks I got your Ebook. I hope I will get better with loops, functions and OOP after reading your ebook. Cheers

chidichiedu
Автор

this is honestly so useful thankyou so much, really clearly explained

adamkenny
Автор

here's how i solved the exercise at 48 min mark:
longest = None
shortest = None
while True:
number = input('Enter a number: ')
if number == 'done':
break
try:
newNumber = float(number)
except:
print("Invalid Input")
continue
if None is longest or newNumber > longest:
longest = newNumber
if None is shortest or newNumber < shortest:
shortest = newNumber
print(longest, shortest)

Nisha-tdcq
Автор

thank you, you have saved another student yet again!

usernamehandle