Exercises 4-12 lp3thw
This commit is contained in:
parent
4e87bc4686
commit
0ca0039bd4
@ -0,0 +1,15 @@
|
||||
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 %d cars available" %cars)
|
||||
print("There are only %d drivers available" %drivers)
|
||||
print("There will be %d empty cars today" %cars_not_driven)
|
||||
print("We can transport %.1f people today" %carpool_capacity)
|
||||
print("We have %d to carpool today" %passengers)
|
||||
print("We have to put about %.1f in each car" %average_passengers_per_car)
|
||||
18
python/lp3thw/Exercise05/ex5.py
Normal file
18
python/lp3thw/Exercise05/ex5.py
Normal file
@ -0,0 +1,18 @@
|
||||
myName = "Ganome"
|
||||
myAge = 35
|
||||
myHeight = 72
|
||||
myWeight = 180
|
||||
myEyes = "Blue"
|
||||
myTeeth = "white"
|
||||
myHair = "Brown"
|
||||
|
||||
print(f"Let's talk about {myName}.")
|
||||
print(f"He's {myHeight} inches tall.")
|
||||
print(f"He's {myWeight} pounds heavy.")
|
||||
print(f"Actually that's not too heavy.")
|
||||
print(f"Hes got {myEyes} eyes and {myHair} hair.")
|
||||
print(f"His teeth are usuallyy {myTeeth} depending on the coffee.")
|
||||
|
||||
#tricky line
|
||||
total = myAge + myHeight + myWeight
|
||||
print(f"If i add {myAge}, {myHeight}, and {myWeight} I get {total}.")
|
||||
21
python/lp3thw/Exercise06/ex6.py
Normal file
21
python/lp3thw/Exercise06/ex6.py
Normal file
@ -0,0 +1,21 @@
|
||||
typesOfPeople = 10
|
||||
x = f"There are {typesOfPeople} types of people"
|
||||
|
||||
binary = "binary"
|
||||
doNot = "don't"
|
||||
y = f"Those who know {binary} and those who {doNot}."
|
||||
|
||||
print(x)
|
||||
print(y)
|
||||
|
||||
print(f"I said: {x}")
|
||||
print(f"I also said: '{y}'") #notice that we can wrap our {} variable in quotes and they still work
|
||||
|
||||
hilarious = False
|
||||
jokeEvaluation = "Isn't that joke so funny! {}"
|
||||
print(jokeEvaluation.format(hilarious))
|
||||
|
||||
w = "This is the left side of ..."
|
||||
e = "A string with a right side."
|
||||
|
||||
print(w + e)
|
||||
22
python/lp3thw/Exercise07/ex7.py
Normal file
22
python/lp3thw/Exercise07/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)
|
||||
|
||||
end1 = "C"
|
||||
end2 = "h"
|
||||
end3 = "e"
|
||||
end4 = "e"
|
||||
end5 = "s"
|
||||
end6 = "e"
|
||||
end7 = "B"
|
||||
end8 = "u"
|
||||
end9 = "r"
|
||||
end10 = "g"
|
||||
end11 = "e"
|
||||
end12 = "r"
|
||||
|
||||
#The comment at the end of the next line is what tells the print command to not start a new line! end=' '
|
||||
print(end1 + end2 + end3 + end4 + end5 + end6)# , end=' ')
|
||||
print(end7 + end8 + end9 + end10 + end11 + end12)
|
||||
|
||||
12
python/lp3thw/Exercise08/ex8.py
Normal file
12
python/lp3thw/Exercise08/ex8.py
Normal file
@ -0,0 +1,12 @@
|
||||
formatter = "{} {} {} {}"
|
||||
|
||||
print(formatter.format(1, 2, 3, 4))
|
||||
print(formatter.format("one", "two", "three", "four"))
|
||||
print(formatter.format(True, False, False, True))
|
||||
print(formatter.format(formatter, formatter, formatter, formatter))
|
||||
print(formatter.format(
|
||||
"MultiLine input",
|
||||
"Is Horrendously Ugly",
|
||||
"To code",
|
||||
"And to read!"
|
||||
))
|
||||
12
python/lp3thw/Exercise09/ex9.py
Normal file
12
python/lp3thw/Exercise09/ex9.py
Normal file
@ -0,0 +1,12 @@
|
||||
days = "Mon Tue Wed Thu Fri Sat Sun"
|
||||
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJuly\nAug"
|
||||
|
||||
print("Here are the days: ", days)
|
||||
print("Here are the months: ", months)
|
||||
|
||||
print( """
|
||||
There's something going on here.
|
||||
With the three double-quites.
|
||||
We'ss be able to typse as much as we like.
|
||||
Even 4 lines if we want. or 5. or 6.
|
||||
""")
|
||||
16
python/lp3thw/Exercise10/Escape-Sequences.txt
Normal file
16
python/lp3thw/Exercise10/Escape-Sequences.txt
Normal file
@ -0,0 +1,16 @@
|
||||
Escape SequencesThis is all of the escape sequences Python supports. You may not use many of these, but memorize
|
||||
their format and what they do anyway. Try them out in some strings to see if you can make them work.Escape What it does.
|
||||
\\Backslash (\)
|
||||
\'Single-quote (')
|
||||
\"Double-quote (")
|
||||
\aASCII bell (BEL)
|
||||
\bASCII backspace (BS)
|
||||
\fASCII formfeed (FF)
|
||||
\nASCII linefeed (LF)
|
||||
\N{name}Character named name in the Unicode database (Unicode only)\rCarriage return (CR)
|
||||
\tHorizontal tab (TAB)
|
||||
\uxxxxCharacter with 16-bit hex value xxxx
|
||||
\UxxxxxxxxCharacter with 32-bit hex value xxxxxxxx
|
||||
\vASCII vertical tab (VT)
|
||||
\000Character with octal value000
|
||||
\xhhCharacter with hex value hh
|
||||
15
python/lp3thw/Exercise10/ex10.py
Normal file
15
python/lp3thw/Exercise10/ex10.py
Normal file
@ -0,0 +1,15 @@
|
||||
tabbyCat = "\tI'm Tabbed in."
|
||||
persianCat = "I'm Split\non a line."
|
||||
backslashCat = "I'm \\ a \\ cat."
|
||||
|
||||
fatCat = """
|
||||
I'll do a list:
|
||||
\t* Cat Food
|
||||
\t* Fishies
|
||||
\t* Catnit\n\t* Grass
|
||||
"""
|
||||
|
||||
print(tabbyCat)
|
||||
print(persianCat)
|
||||
print(backslashCat)
|
||||
print(fatCat)
|
||||
8
python/lp3thw/Exercise11/ex11.py
Normal file
8
python/lp3thw/Exercise11/ex11.py
Normal file
@ -0,0 +1,8 @@
|
||||
print("How old are you?", end=' ')
|
||||
age = input()
|
||||
print("How tall are you?", end=' ')
|
||||
height = input()
|
||||
print("How much do you weigh?", end=' ')
|
||||
weight = input()
|
||||
|
||||
print(f"So you are {age} years old, {height} tall and {weight} heavy.")
|
||||
6
python/lp3thw/Exercise12/ex12.py
Normal file
6
python/lp3thw/Exercise12/ex12.py
Normal file
@ -0,0 +1,6 @@
|
||||
age = input("How old are you? ")
|
||||
height = input("How tall are you?")
|
||||
weight = input("How much do you weight?")
|
||||
|
||||
|
||||
print(f"So, you're {age} old, {height} tall, and {weight} heavy/")
|
||||
Loading…
x
Reference in New Issue
Block a user