python the hard way ex.
This commit is contained in:
parent
7b39b906fb
commit
dab9fe5912
9 changed files with 133 additions and 0 deletions
8
sami/learn-python-the-hard-way/ex1.py
Normal file
8
sami/learn-python-the-hard-way/ex1.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
print("Hello World!")
|
||||
print("Hello Again")
|
||||
print("I like typing this.")
|
||||
print("This is fun.")
|
||||
print('Yay! Printing.')
|
||||
print("I'd much rather you 'not'.")
|
||||
print('I "said" do not touch this.')
|
9
sami/learn-python-the-hard-way/ex2.py
Normal file
9
sami/learn-python-the-hard-way/ex2.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
# A comment, this is so you can read your program later.
|
||||
# Anything after the # is ignored by python.
|
||||
|
||||
print("I could have code like this.") # and the comment after is ignored
|
||||
|
||||
# You can also use a comment to "disable" or comment out code:
|
||||
# print("This won't run.")
|
||||
|
||||
print("This will run.")
|
30
sami/learn-python-the-hard-way/ex3.py
Normal file
30
sami/learn-python-the-hard-way/ex3.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
print("I will now count my chickens:")
|
||||
|
||||
|
||||
print("Hens", 25 + 30 / 6)
|
||||
print("Roosters", 100 - 25 * 3 % 4)
|
||||
|
||||
|
||||
print("Now I will count the eggs:")
|
||||
|
||||
|
||||
print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)
|
||||
|
||||
|
||||
|
||||
print("Is it true that 3 + 2 < 5 - 7?")
|
||||
|
||||
print(3 + 2 < 5 - 7)
|
||||
|
||||
|
||||
|
||||
print("What is 3 + 2?", 3 + 2)
|
||||
print("What is 5 - 7?", 5 - 7)
|
||||
|
||||
print("Oh, that's why it's False.")
|
||||
|
||||
print("How about some more.")
|
||||
|
||||
print("Is it greater?", 5 > -2)
|
||||
print("Is it greater or equal?", 5 >= -2)
|
||||
print("Is it less or equal?", 5 <= -2)
|
16
sami/learn-python-the-hard-way/ex4.py
Normal file
16
sami/learn-python-the-hard-way/ex4.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
cars = 100
|
||||
space_in_a_car = 4.0
|
||||
drivers = 30
|
||||
passengers = 90
|
||||
cars_not_driven = cars - drivers
|
||||
cars_driven = drivers
|
||||
carpool_capacity = cars_driven * space_in_a_car
|
||||
average_passengers_per_car = passengers / cars_driven
|
||||
|
||||
print("There are", cars, "cars available.")
|
||||
print("There are only", drivers, "drivers available.")
|
||||
print("There will be", cars_not_driven, "empty cars today.")
|
||||
print("We can transport", carpool_capacity, "people today.")
|
||||
print("We have", passengers, "to carpool today.")
|
||||
print("We need to put about", average_passengers_per_car,
|
||||
"in each car.")
|
18
sami/learn-python-the-hard-way/ex5.py
Normal file
18
sami/learn-python-the-hard-way/ex5.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
my_name = 'Zed A. Shaw'
|
||||
my_age = 35 # not a lie
|
||||
my_height = 74 # inches
|
||||
my_weight = 180 # lbs
|
||||
my_eyes = 'Blue'
|
||||
my_teeth = 'White'
|
||||
my_hair = 'Brown'
|
||||
|
||||
print(f"Let's talk about {my_name}.")
|
||||
print(f"He's {my_height} inches tall.")
|
||||
print(f"He's {my_weight} pounds heavy.")
|
||||
print("Actually that's not too heavy.")
|
||||
print(f"He's got {my_eyes} eyes and {my_hair} hair.")
|
||||
print(f"His teeth are usually {my_teeth} depending on the coffee.")
|
||||
|
||||
# this line is tricky, try to get it exactly right
|
||||
total = my_age + my_height + my_weight
|
||||
print(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}.")
|
26
sami/learn-python-the-hard-way/ex6.py
Normal file
26
sami/learn-python-the-hard-way/ex6.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
types_of_people = 10
|
||||
x = f"There are {types_of_people} types of people."
|
||||
|
||||
binary = "binary"
|
||||
do_not = "don't"
|
||||
y = f"Those who know {binary} and those who {do_not}."
|
||||
|
||||
print(x)
|
||||
print(y)
|
||||
|
||||
print(f"I said: {x}")
|
||||
print(f"I also said: '{y}'")
|
||||
|
||||
|
||||
hilarious = False
|
||||
|
||||
|
||||
joke_evaluation = "Isn't that joke so funny?! {}"
|
||||
|
||||
|
||||
print(joke_evaluation.format(hilarious))
|
||||
|
||||
w = "This is the left side of..."
|
||||
e = "a string with a right side."
|
||||
|
||||
print(w + e)
|
22
sami/learn-python-the-hard-way/ex7.py
Normal file
22
sami/learn-python-the-hard-way/ex7.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
print("Mary had a little lamb.")
|
||||
print("Its fleece was white as {}.".format('snow'))
|
||||
print("And everywhere that Mary went.")
|
||||
print("." * 10)
|
||||
# what'd that do?
|
||||
|
||||
end1 = "C"
|
||||
end2 = "h"
|
||||
end3 = "e"
|
||||
end4 = "e"
|
||||
end5 = "s"
|
||||
end6 = "e"
|
||||
end7 = "B"
|
||||
end8 = "u"
|
||||
end9 = "r"
|
||||
end10 = "g"
|
||||
end11 = "e"
|
||||
end12 = "r"
|
||||
|
||||
# watch end = ' ' at the end. try removing it to see what happens
|
||||
print(end1 + end2 + end3 + end4 + end5 + end6, end=' ')
|
||||
print(end7 + end8 + end9 + end10 + end11 + end12)
|
Binary file not shown.
4
sami/learn-python-the-hard-way/python.org
Normal file
4
sami/learn-python-the-hard-way/python.org
Normal file
|
@ -0,0 +1,4 @@
|
|||
* Python
|
||||
** Numbers and Math: Every programming language has some kind of way doing numbers and math
|
||||
** Variables and Names : we need to use underscore with means an imaginary space between words in variable names
|
||||
** a variable is nothing more than a name for something.
|
Loading…
Reference in a new issue