Skip to content

Commit a3ad43f

Browse files
committed
init commit
1 parent 49da4c6 commit a3ad43f

File tree

7 files changed

+249
-0
lines changed

7 files changed

+249
-0
lines changed

15. common errors.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
'''
2+
Hello and welcome to another python 3 basics video.
3+
4+
In this video we'll be discussing some of the basics to
5+
debugging. In my videos, I get a lot of questions for
6+
help where people have errors and are not sure what
7+
the problem is. If they used some extremely simple debugging,
8+
they'd realize how obvious the answer is.
9+
10+
Most of the time, the problem is a typo, followed closely by
11+
a misunderstanding of indentation and standards.
12+
13+
so standards how are how organize your code. With python,
14+
unlike most languages, you define blocks of code like
15+
functions by indentation. Most python editors will automatically
16+
indent for you where it is necessary. With this, if you are ever
17+
coding along and find python automatically indenting you where
18+
you don't think it should, this should raise a flag for you to
19+
figure out.
20+
21+
22+
(show a basic function... )
23+
24+
There are some more in-depth common-issues that you'll
25+
find from time to time, you can find more debugging videos
26+
by searching for debuggin in my channel. For now I will just
27+
keep these ones basic.
28+
29+
The first error we'll discuss is the NameError: is not defined
30+
31+
'''
32+
33+
'''
34+
As obvious as this might appear to you, this gets people amazingly
35+
frequently. Just learn to recognize the "is not defined"
36+
37+
chances are you typoed the definition of the variable or when you
38+
are referring to it.
39+
'''
40+
variable = 55
41+
#print(varaible)
42+
43+
44+
'''
45+
Next up, we have indentation issues.
46+
47+
You will see "expected an indented block" as a
48+
popup when you never enter an indented block for
49+
something that requires it, like a function.
50+
'''
51+
52+
'''
53+
def task1():
54+
55+
56+
def task2():
57+
print('more tasks')
58+
59+
'''
60+
61+
62+
'''
63+
unexpected indent...
64+
'''
65+
66+
def task():
67+
print ('stuff')
68+
69+
print('more stuff')
70+
71+
print('stuff')
72+
73+
74+
75+
'''
76+
EOL while scanning string literal
77+
'''
78+
79+
80+
def task():
81+
print('some people find themselves committing this too
82+
83+
84+
print('ouch...')
85+
86+
87+
88+

16. writing to a file.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'''
2+
Hello and welcome to another python 3 basics tutorial video.
3+
4+
In this video we're going to cover the basics of writing to a file.
5+
6+
It should be noted that there are two methods for saving data to a file, and
7+
those are writing and appending. Writing to a file will write that bit
8+
of data, whatever it is, solely, to the file. This means if there was anything
9+
there before, it will be gone if you use write.
10+
11+
If you use append, then you will basically add to whatever is previously there.
12+
13+
I will be showing both methods, but write first.
14+
'''
15+
16+
17+
# so here we have some simple text, but we also threw in a \n to
18+
# denote a new line, this will start a newline in the file that we write to
19+
text = 'Sample Text to Save\nNew line!'
20+
21+
# notifies Python that you are opening this file, with the intention to write
22+
saveFile = open('exampleFile.txt','w')
23+
# actually writes the information
24+
saveFile.write(text)
25+
# It is important to remember to actually close the file, otherwise it will
26+
# hang for a while and could cause problems in your script
27+
saveFile.close()
28+
29+

17. appending to a file.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'''
2+
Alright, so now we get to appending a file in python. I will just state again
3+
that writing will clear the file and write to it just the data you specify in
4+
the write operation. Appending will simply take what was already there, and add
5+
to it.
6+
7+
That said, when you actually go to add to the file, you will still use
8+
.write... you only specify that you will be appending instead of writing
9+
when you open the file and specify your intentions.
10+
11+
'''
12+
13+
14+
# so here, generally it can be a good idea to start with a newline, since
15+
# otherwise it will append data on the same line as the file left off.
16+
# you might want that, but I'll use a new line.
17+
# another option used is to first append just a simple newline
18+
# then append what you want.
19+
appendMe = '\nNew bit of information'
20+
21+
appendFile = open('exampleFile.txt','a')
22+
appendFile.write(appendMe)
23+
appendFile.close()
24+

18. readingFiles.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
So now that you know how to write and append files, we can learn how
3+
to read from files!
4+
'''
5+
6+
# similar syntax as you've seen, 'r' for read. You can just throw a .read() at
7+
# the end, and you get:
8+
readMe = open('exampleFile.txt','r').read()
9+
print(readMe)
10+
11+
12+
'''
13+
Now that is great and useful, but a lot of times people want to read by line.
14+
There are a few things you can do here, but probably the easiest is to:
15+
'''
16+
17+
# this will instead read the file into a python list.
18+
readMe = open('exampleFile.txt','r').readlines()
19+
print(readMe)
20+

19. classes.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class calculator:
2+
3+
def addition(x,y):
4+
added = x + y
5+
print(added)
6+
7+
def subtraction(x,y):
8+
sub = x - y
9+
print(sub)
10+
11+
def multiplication(x,y):
12+
mult = x * y
13+
print(mult)
14+
15+
def division(x,y):
16+
div = x / y
17+
print(div)
18+
19+
20+
21+
22+
23+
24+
'''
25+
>>> calculator.subtraction(5,8)
26+
-3
27+
>>> calculator.multiplication(3,5)
28+
15
29+
>>> calculator.division(5,3)
30+
1.6666666666666667
31+
>>> calculator.addition(5,2)
32+
7
33+
>>>
34+
35+
'''
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+

20. user input.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''
2+
Sometimes in basic gui, or graphical user interphase, applications,
3+
some input from a user might be wanted. To do this, we use the
4+
built-in input functionality with python 3. If you are familiar with Python 2.7,
5+
the python 3 input function acts like the python 2 raw_input function.
6+
'''
7+
8+
9+
x = input('test:')
10+
11+
print(x)
12+
13+
14+
# simple enough

21. more math.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'''
2+
Python is a very popular programming language for data processing of many types
3+
With data processing, a lot of math is used often times. So, besides the basic
4+
math, we should cover some more in depth operations. Luckily for us, python 3
5+
has some great built in modules that we can utilize.
6+
'''
7+
8+
import statistics
9+
10+
example_list = [5,2,5,6,1,2,6,7,2,6,3,5,5]
11+
12+
x = statistics.mean(example_list)
13+
print(x)
14+
15+
y = statistics.median(example_list)
16+
print(y)
17+
18+
z = statistics.mode(example_list)
19+
print(z)
20+
21+
a = statistics.stdev(example_list)
22+
print(a)
23+
24+
b = statistics.variance(example_list)
25+
print(b)
26+
27+
28+

0 commit comments

Comments
 (0)