Exercises 4-12 lp3thw

This commit is contained in:
Ganome 2021-04-19 17:06:12 +00:00
parent 4e87bc4686
commit 0ca0039bd4
10 changed files with 145 additions and 0 deletions

View File

@ -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)

View 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}.")

View 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)

View 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)

View 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!"
))

View 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.
""")

View 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

View 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)

View 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.")

View 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/")