Skip to content

Commit 2e0d039

Browse files
committed
adding repos
1 parent 118b185 commit 2e0d039

File tree

17 files changed

+365
-1
lines changed

17 files changed

+365
-1
lines changed

BootDevPython/Ch1/first.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Python course from BootDev
2+
3+
print("Welcome to fantasy Quest")
4+
5+
# first bug
6+
sword_damage = 10
7+
player_health = 100
8+
health_after_attack = player_health - sword_damage
9+
print(f"Lollifriend's health is: {player_health}")
10+
print(f"Lollifriend is hit by a sword for {sword_damage} damage ...")
11+
print(f"Lollifriend's health is now: {health_after_attack}")
12+
13+
# the console
14+
answer = 2 + 2
15+
print(answer)
16+
print('Use the arrow keys to move around')
17+
# what is code?
18+
print(4 + 5)
19+
print(250 + 75 )
20+
# syntax
21+
22+
23+

BootDevPython/Ch2/2nd.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# variables -value can change
2+
3+
player_health = 1000
4+
print(player_health)
5+
6+
# reduce by 100 here
7+
print(player_health - 100 )
8+
9+
player_health = 800
10+
print(player_health)
11+
12+
player_health = 700
13+
print(player_health)
14+
player_health = 600
15+
print(player_health)
16+
17+
# math
18+
player_health = 1000
19+
armour_multiplier = 2
20+
21+
# create armoured_health here
22+
armoured_health = player_health * armour_multiplier
23+
print(armoured_health)
24+
25+
player_health = 100
26+
poison_damage = - 10
27+
28+
player_poison_health = player_health + poison_damage
29+
print(player_poison_health)
30+
31+
# the best_sword var holds the value of the best sword in the game
32+
best_sword = "scimitar"
33+
print(best_sword)
34+
35+
# variable names
36+
my_name = "Trash Puppy"
37+
38+
#camelCase - convention used in Python
39+
variableName = 'TP'
40+
#snake_case
41+
42+
variable_name = 'TP'
43+
44+
# SCREAMING_SNAKE_CASE
45+
VARIABLE_NAME = 'TP'
46+
47+
player_has_magic = True # 1 == true, 0 == false
48+
print(f"player_has_health is a/an {type(player_health)}")
49+
print(f"player_has_magic is a/an {type(player_has_magic)}")
50+
51+
# F-strings in Python (formatted strings)
52+
name = "Trash Puppy"
53+
height = "6ft"
54+
55+
# print("My name is " + name + "and I am " + height + "tall!")
56+
57+
print(f"My name is {name} and I am {height} tall!")
58+
59+
name = "Yarl"
60+
age = 37
61+
race = "dwarf"
62+
63+
print(f"{name} is a {race} who is {age} years old.")
64+
65+
# Nonetype variables / used to set a default value that you expect to
66+
# / will change later
67+
68+
# (None = absence of any value)
69+
enemy = None
70+
71+
print(enemy is None)
72+
print(enemy is not None)
73+
74+
# Dynamic Typing - the type of value in stored in variables can change
75+
76+
speed = 5 # integer type
77+
78+
speed = "five" # string type
79+
80+
# math with strings
81+
sentence_start = "You have "
82+
sentence_end = " health"
83+
84+
player1_health = "1200"
85+
player2_health = "1100"
86+
87+
print(sentence_start + player1_health + sentence_end)
88+
# print(sentence_start * 6)
89+
print(sentence_start + player2_health + sentence_end)
90+
91+
# Multi-Variable Declaration
92+
sword_name, sword_damage, sword_length = "Excalibur", 10 , 200
93+
94+
# the above is identical to:
95+
sword_name = "Excalibur"
96+
sword_damage = 100
97+
sword_length = 200

BootDevPython/Ch3/3b.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def area_of_circle(dog): # python is expecting one value(radius)
2+
# and thus you can rename it (here 'dog'instead of r, or radius)
3+
4+
pi = 3.14
5+
result = pi * dog * dog
6+
return result
7+
8+
9+
radius = 5
10+
area = area_of_circle(radius) # argument you call in the function
11+
# (in this ex. radius), it must have the same
12+
# name as the variable name you want to pass into it.
13+
# However, in the area_of_circle func
14+
# python knows the value you pass into the first function (area_of_circle)
15+
# is the same, and thus you can rename it (her 'dog')
16+
17+
# more precisely: Only the VALUE of the variable is passed to
18+
# the function. It is then assigned to a new variable called 'dog'.
19+
20+
print(area)
21+

BootDevPython/Ch3/3rd.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Functions - allow for reusing and organizing code.
2+
def area_of_circle(radius) -> int: # radius is a parameter (or argument)
3+
pi = 3.14
4+
area = pi * radius * radius
5+
return area # n.b.: is also the end of the function body
6+
7+
8+
sword_length = 1.0
9+
spear_length = 2.0
10+
11+
sword_area = area_of_circle(sword_length) # here area_of_circle is the function,
12+
# sword_length is an argument (or parameter)
13+
spear_area = area_of_circle(spear_length)
14+
15+
print("Sword length:", sword_length, "meters.")
16+
print("Sword attack area:", sword_area, "square meters")
17+
18+
print("Spear length:", spear_length, "meters.")
19+
print("spear attack area:", spear_area, "square meters")
20+
21+
if __name__ == "__main__":
22+
print("This is the Functions module, aka Ch3")
23+

BootDevPython/Ch3/convert.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def to_celsius(f) -> int | float:
2+
celsius: int | float = (5/9) * (f - 32)
3+
return celsius
4+
5+
6+
def test(f):
7+
c: int | float = round(to_celsius(f), 2)
8+
print(f, "degrees fahrenheit is", c, "degrees celsius")
9+
10+
11+
test(100)
12+
test(88.5)
13+
test(104)
14+
test(112)
15+
16+
# Function calls
17+
# damage1 = calculate_damage(10, 20, 30)
18+
# damage2 = calculate_damage(5,10, 15)
19+
20+
test1 = to_celsius(32)
21+
test2 = to_celsius(212)
22+
23+
print(f"test1 equals: {test1}")
24+
print(f"test2 equals: {test2}")
25+
26+
# Terminology
27+
# values passed into a function "parameters" or "arguments"

BootDevPython/Ch3/declare.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
def main():
4+
print("Fantasy Quest is booting up...")
5+
print("Game is running")
6+
health = 10
7+
armour = 5
8+
add_armour(health, armour)
9+
10+
def add_armour(h, a):
11+
new_health = h + a
12+
print_health(new_health)
13+
14+
def print_health(new_health):
15+
print(f"The player now has {new_health} health")
16+
17+
18+
19+
20+
# call entrypoint last
21+
main()
22+
23+

BootDevPython/Ch3/hrs.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def hours_to_seconds(hours) -> int:
2+
minutes: int = hours * 60
3+
seconds: int = minutes * 60
4+
5+
return seconds
6+
7+
8+
def test(hours) -> int:
9+
secs: int = hours_to_seconds(hours)
10+
print(hours, "hours is", secs, "seconds")
11+
12+
13+
test(10)
14+
test(1)
15+
test(25)
16+
test(100)

BootDevPython/Ch3/multiple.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Multiple Return values
2+
3+
def become_warrior(first_name: str, last_name: str, power: int):
4+
title: str = f"{first_name} {last_name} the warrior"
5+
6+
new_power: str | int = power + 1
7+
8+
return title, new_power
9+
10+
11+
def main():
12+
test("Frodo","Baggins", 5 )
13+
test("Bilbo","Baggins", 10 )
14+
test("Gandalf","The Grey", 9000 )
15+
16+
def test(first_name, last_name, power):
17+
title, new_power = become_warrior(first_name, last_name, power)
18+
print(title, "has a power level of:", new_power)
19+
20+
21+
main()

BootDevPython/Ch3/multparam.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# multiple paramaters
2+
3+
def subtract(a, b):
4+
result = a - b
5+
return result
6+
7+
result = subtract(5, 3)
8+
print (result)
9+
10+
# N.B. multiple parameters cab be given, but
11+
# the order of values passed into the parameters matters.
12+
# the first parameter is the first value you pass in,
13+
# the second parameter is the second value you pass in.
14+
15+
# e.g. a = 5, b = 3
16+
17+
18+
###############################
19+
damage_one: int = 2 # added type annotation
20+
damage_two = 4
21+
damage_three: float = 3.5 # added a float, note that annotation in triple_attack func below
22+
damage_four = -1
23+
damage_five = 10
24+
damage_six = 5
25+
26+
def triple_attack(slash_one, slash_two, slash_three: list[int | float]) -> int | float: # added type annotation
27+
total_dmg = slash_one + slash_two + slash_three
28+
return total_dmg
29+
30+
31+
result = triple_attack(2, damage_two, 89.9) # values can be passed either as raw value, or as var
32+
print(f"Result = {result}")
33+
34+
35+
36+
print("Getting damage for", damage_one, damage_two,"and", damage_three, '...')
37+
print(triple_attack(damage_one, damage_two, damage_three), "points of damage dealt!")
38+
print("==========================================")
39+
40+
print("Getting damage for", damage_four, damage_five,"and", damage_six, '...')
41+
print(triple_attack(damage_four, damage_five, damage_six), "points of damage dealt!")
42+
print("==========================================")

BootDevPython/Ch3/none.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def my_func():
2+
print("I do nothing")
3+
return home
4+
5+
def my_func2():
6+
print("Still doing niente")
7+
return
8+
9+
def my_func3():
10+
print("You guessed it...")
11+
12+
13+
14+
# all of the above return an empty value "None"
15+
16+
# Terms:
17+
18+
# Print: shows a value in the console.
19+
# Return: makes a value available to the caller of the function.
20+
21+

BootDevPython/Ch3/paramargs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Parameters vs Arguments
2+
3+
# Parameters are the names used for inputs when defining a function.
4+
# (the inputs specified by the function definition)
5+
6+
# Arguments are the values of the inputs supplied when a function is called.
7+
# - the actual values being passed into the function
8+
9+
# a and b are parameters
10+
def add(a, b):
11+
return a + b
12+
13+
14+
# 5 and 6 are arguments
15+
sum = add(5, 6)

BootDevPython/next.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# start with ch3
2+
continue at timestamp: 1:09:40 "Default values for function args"

Designer_Mindset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit e583456fd2eb62a3814ad673a630ebd34f73463a
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import socket
2+
3+
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4+
mysock.connect(('data.pr4e.org', 80))
5+
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\n\n'.encode()
6+
mysock.send(cmd)
7+
8+
while True:
9+
data = mysock.recv(512)
10+
if (len(data) < 1):
11+
break
12+
print(data.decode())
13+
mysock.close()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import socket
2+
3+
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4+
mysock.connect(('data.pr4e.org', 80))
5+
cmd = 'GET http://data.pr4e.org/romeo.txt HTTP/1.0\r\n\r\n'.encode()
6+
mysock.send(cmd)
7+
8+
while True:
9+
data = mysock.recv(512)
10+
if (len(data)) < 1:
11+
break
12+
print(data.decode())
13+
mysock.close()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# built in TCP Socket support
2+
3+
import socket
4+
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5+
mysock.connect( ('data.pr4e.org', 80))
6+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Python_projects
22
![Python](https://a11ybadges.com/badge?logo=python)
3-
Various Python Projects
3+
Various Python Books, Courses, Excercises, etc. for learning Python

0 commit comments

Comments
 (0)