Skip to content

Commit 5773599

Browse files
committed
Python Crash Course init Commit
0 parents  commit 5773599

File tree

75 files changed

+2200
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2200
-0
lines changed

01_variables/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Variables
2+
## Variables helps us to store key&value information that we would like to refer to its value throughout the program
3+
```python
4+
name = "Michael"
5+
age = 30
6+
7+
print(name, "is my name")
8+
print(name, "is", age, "years old")
9+
print(name, "likes to eat pizza")
10+
print("This man's name is", name)
11+
12+
13+
14+
```
15+
## Exercise:
16+
17+
### Is there a way that you can create more than one variable in one line of code ? Worth to search on web if this could be done!
18+
19+
### Answer:
20+
```python
21+
a, b, c = 1,2,3 # a will receive 1, b will receive 2, c will receive 3
22+
#More examples:
23+
print(a)
24+
print(b)
25+
print(c)
26+
27+
name, age = "Jim", 25
28+
print(name)
29+
print(age)
30+
```

01_variables/code.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#Variables
2+
3+
#Variables helps us to store key&value information that we would like to refer to its value throughout the program
4+
5+
6+
name = "Michael"
7+
age = 30
8+
9+
print(name, "is my name")
10+
print(name, "is", age, "years old")
11+
print(name, "likes to eat pizza")
12+
print("This man's name is", name)
13+
14+

02_types_and_conversions/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Types and Conversions
2+
## We can divide in any programming language some variable types into categories
3+
```python
4+
#All types:
5+
name = "John" #Strings - Characters that we want to create/store variables
6+
age = 30 #Integers - Numbers without decimal point
7+
temperature = 90.5 #Floating Numbers / Floats - Numbers with decimal point
8+
is_raining = False #Booleans - Describes a situation - True or False
9+
10+
#str() - Will convert to string
11+
#int() - Will convert to integers
12+
#float() - Will convert to floating numbers
13+
#bool() - Will convert to booleans
14+
15+
#Temperature average program:
16+
temperature1 = 95.5
17+
temperature2 = 94.5
18+
average = (temperature1 + temperature2) / 2
19+
print(int(average))
20+
21+
#Concatenate digits program:
22+
digit_one = 1
23+
digit_two = 2
24+
print(str(digit_one) + str(digit_two))
25+
26+
```

02_types_and_conversions/code.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#Types and Conversions
2+
3+
#We can divide in any programming language some variable types into categories
4+
5+
6+
#All types:
7+
name = "John" #Strings - Characters that we want to create/store variables
8+
age = 30 #Integers - Numbers without decimal point
9+
temperature = 90.5 #Floating Numbers / Floats - Numbers with decimal point
10+
is_raining = False #Booleans - Describes a situation - True or False
11+
12+
#str() - Will convert to string
13+
#int() - Will convert to integers
14+
#float() - Will convert to floating numbers
15+
#bool() - Will convert to booleans
16+
17+
#Temperature average program:
18+
temperature1 = 95.5
19+
temperature2 = 94.5
20+
average = (temperature1 + temperature2) / 2
21+
print(int(average))
22+
23+
#Concatenate digits program:
24+
digit_one = 1
25+
digit_two = 2
26+
print(str(digit_one) + str(digit_two))

03_input/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Input built in function
2+
## Input built-in function allows to receive input from the user while the programs runs. Program won't resume till you put your input
3+
```python
4+
#We always want to assign the input built-in function to a variable
5+
answer = input("How is the weather today")
6+
print("The weather today is ", answer)
7+
8+
#You can force your inputs to receive specific types of variables:
9+
current_year = 2021
10+
answer = int(input("What is your age?")) # We could use any built-in conversion function here we'd like
11+
print("Your year of birth is", current_year - answer)
12+
13+
14+
15+
```
16+
## Exercise:
17+
18+
### Write a program that will receive three inputs, grade_one, grade_two, grade_three. Try to write a program that will print the average of the received three grades.
19+
20+
### Answer:
21+
```python
22+
#We need to force each input to be integers (float would also work)
23+
grade_one = int(input("What is the first grade?"))
24+
grade_two = int(input("What is the second grade?"))
25+
grade_three = int(input("What is the third grade?"))
26+
27+
avg = (grade_one + grade_two + grade_three) / 3
28+
print("Average is:", avg)
29+
```

03_input/code.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Input built in function
2+
3+
#Input built-in function allows to receive input from the user while the programs runs. Program won't resume till you put your input
4+
5+
6+
#We always want to assign the input built-in function to a variable
7+
answer = input("How is the weather today")
8+
print("The weather today is ", answer)
9+
10+
#You can force your inputs to receive specific types of variables:
11+
current_year = 2021
12+
answer = int(input("What is your age?")) # We could use any built-in conversion function here we'd like
13+
print("Your year of birth is", current_year - answer)
14+
15+

04_formatted_strings/code.py

1.77 KB
Binary file not shown.

05_methods/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Methods
2+
## Different variable types are going to have their unique methods
3+
```python
4+
#This is the name of our person:
5+
name = "John doe"
6+
7+
#Say that we want this person to have the name spelled as it supposed to be: John Doe
8+
#We can launch this method:
9+
10+
print(name.title()) # Will print John Doe
11+
12+
#We might think that once you launch this method on the variable, it will override it for the rest of the program
13+
14+
#BUT:
15+
#Lets write this program now:
16+
17+
name_two = "John doe"
18+
name_two.title()
19+
print(name_two) # This line will STILL show: John doe
20+
21+
#Reason:
22+
#Not all the methods out there, will affect the value of the variable that you apply the method on.
23+
24+
#To really override the value itself, we can launch this:
25+
26+
name_three = 'John doe'
27+
name_three = name_three.title()
28+
print(name_three) # This line will print John Doe
29+
```

05_methods/code.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Methods
2+
3+
#Different variable types are going to have their unique methods
4+
5+
6+
#This is the name of our person:
7+
name = "John doe"
8+
9+
#Say that we want this person to have the name spelled as it supposed to be: John Doe
10+
#We can launch this method:
11+
12+
print(name.title()) # Will print John Doe
13+
14+
#We might think that once you launch this method on the variable, it will override it for the rest of the program
15+
16+
#BUT:
17+
#Lets write this program now:
18+
19+
name_two = "John doe"
20+
name_two.title()
21+
print(name_two) # This line will STILL show: John doe
22+
23+
#Reason:
24+
#Not all the methods out there, will affect the value of the variable that you apply the method on.
25+
26+
#To really override the value itself, we can launch this:
27+
28+
name_three = 'John doe'
29+
name_three = name_three.title()
30+
print(name_three) # This line will print John Doe

06_string_methods/README.md

Whitespace-only changes.

06_string_methods/code.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#String Methods:
2+
3+
#String has its unique methods to display them in different ways
4+
5+
6+
#Here are some example you can try to execute:
7+
8+
#.title() - Will capitalize each word on the string
9+
#.capitalize() - Will capitalize the first letter ONLY
10+
#.upper() - Will turn all letters in uppercase
11+
#.lower() - Will turn all lower in uppercase
12+
name = "John doe"
13+
print(f"Title: {name.title()}")
14+
print(f"Capitalize: {name.capitalize()}")
15+
print(f"Upper: {name.upper()}")
16+
print(f"Lower: {name.lower()}")
17+
18+
19+
###PRACTICE###
20+
#Q: Is there a way to see how many characters we have inside a string ? Try to search for a way to do so.
21+
course_name = "JimShapedCoding" # We should find a python built-in function that will automatically count the characters, and give us back 15
22+
#A:
23+
#len - A built-in function that will allow us to count the number of characters in a string. We will use the len built-in function as well in more complex variable types that we will learn in the future
24+
course_name_length = len(course_name)
25+
print(course_name_length) #Will return 15

07_math_operations/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Math Operators
2+
## Most of the known arithmetic operations are available to use like in real life math
3+
```python
4+
#type() - A built-in function that will give us back the
5+
#type of a specific variable
6+
7+
# Addition - 3 + 2
8+
# Subtraction - 3 + 2
9+
# Division - 3 / 2 (Will return float)
10+
# Division without Remainder - 3 // 2
11+
# Multiply - 3 * 2
12+
# Power - 3 ** 2
13+
# Modulus - 3 % 2
14+
15+
16+
action = 3 + 2 # Change the operation to what you want to test out
17+
print(f'Result is: {action}')
18+
```

07_math_operations/code.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#Math Operators
2+
3+
#Most of the known arithmetic operations are available to use like in real life math
4+
5+
6+
#type() - A built-in function that will give us back the
7+
#type of a specific variable
8+
9+
# Addition - 3 + 2
10+
# Subtraction - 3 + 2
11+
# Division - 3 / 2 (Will return float)
12+
# Division without Remainder - 3 // 2
13+
# Multiply - 3 * 2
14+
# Power - 3 ** 2
15+
# Modulus - 3 % 2
16+
17+
18+
action = 3 + 2 # Change the operation to what you want to test out
19+
print(f'Result is: {action}')

08_imports/README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Imports
2+
## There are tons of external libraries in Python that you can use them by calling it's name using the built-in keyword import
3+
```python
4+
import math
5+
6+
#For example, say that we want to perform some more complex
7+
#Math operations, than we can go and import the math library
8+
#And use its additional functionalities like that:
9+
a = 8.2
10+
b = math.floor(a)
11+
c = math.ceil(a)
12+
print(b)
13+
print(c)
14+
15+
#Remember, there are some more ways that you can import
16+
#Additional functionalities.
17+
#You can refer to the specific function that you want to import
18+
#FROM an external library
19+
20+
from math import ceil
21+
22+
#And then use it like:
23+
24+
d = 8.2
25+
e = ceil(d)
26+
print(e)
27+
28+
#But that approach is less common, since the
29+
#Python will load the entire library anyway.
30+
#We could think that importing specific function could improve
31+
#the time run of our program, but this is not the case
32+
```

08_imports/code.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#Imports
2+
3+
#There are tons of external libraries in Python that you can use them by calling it's name using the built-in keyword import
4+
5+
6+
import math
7+
8+
#For example, say that we want to perform some more complex
9+
#Math operations, than we can go and import the math library
10+
#And use its additional functionalities like that:
11+
a = 8.2
12+
b = math.floor(a)
13+
c = math.ceil(a)
14+
print(b)
15+
print(c)
16+
17+
#Remember, there are some more ways that you can import
18+
#Additional functionalities.
19+
#You can refer to the specific function that you want to import
20+
#FROM an external library
21+
22+
from math import ceil
23+
24+
#And then use it like:
25+
26+
d = 8.2
27+
e = ceil(d)
28+
print(e)
29+
30+
#But that approach is less common, since the
31+
#Python will load the entire library anyway.
32+
#We could think that importing specific function could improve
33+
#the time run of our program, but this is not the case

09_expressions/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Expressions
2+
## Expressions will allow us to define different situations on our program, that will give us back the value of True or False
3+
```python
4+
#Expressions usually are going to be described with at least one of the following operators
5+
6+
# == Equal
7+
# != Not equal
8+
# > Greater than
9+
# < Less than
10+
# >= Greater than or equal to
11+
# <= Less than or equal to
12+
13+
# There are some more keyworded operators that we will look what they do in the future
14+
15+
print(5 == 5) #True
16+
print(5 != 5) #False
17+
print(5 > 5) #False
18+
print(5 < 5) #False
19+
print(5 >= 5) #True
20+
print(5 <= 5) #True
21+
```

09_expressions/code.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#Expressions
2+
3+
#Expressions will allow us to define different situations on our program, that will give us back the value of True or False
4+
5+
6+
#Expressions usually are going to be described with at least one of the following operators
7+
8+
# == Equal
9+
# != Not equal
10+
# > Greater than
11+
# < Less than
12+
# >= Greater than or equal to
13+
# <= Less than or equal to
14+
15+
# There are some more keyworded operators that we will look what they do in the future
16+
17+
print(5 == 5) #True
18+
print(5 != 5) #False
19+
print(5 > 5) #False
20+
print(5 < 5) #False
21+
print(5 >= 5) #True
22+
print(5 <= 5) #True

0 commit comments

Comments
 (0)