Learn python3 the hard way(simple notes)

Exercise 1

print('I am happy to see you here')
print( " I 'd like to see you here")
print("I am not talking to ' you'.")
print('i"am" happy to see you')

Exercise 2

print('I will now count my hens:')
print('Hens:',25+30/6)
print('Roosters:',100-25*3/4)
print("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 is greater?",5>-2)
print("Is it greater or equal?", 5 >= -2)
print("Is it less or equal?", 5 <= -2)

Exercise 3

my_name = 'lol'
my_age = '24' # which is true
my_height = '175'
my_weight = '116'
my_eyes = 'Brown'
my_hair ='Black'

print(f"Let us talk about {my_name}.")
print(f"He's {my_height} cm tall")
print(f"He's {my_weight} grams heavy")
print(f"He's got {my_eyes} eyes and {my_hair} hair")
print("I love this guy!")

Exercise 4

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 wih a right side."}

print( w +e)

Exercise 5

print("Marry had a little lamb.")
print("Its fleece was white as {}.format('show'))
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"

print( end1+end2+end3+end4+end5+end6, end =' ')
print(end7+end8+end9+end10+end11+end12)

Exercise 6

formatter = "{} {} {} {}"

print(formatter.format(1,2,3,4))
print(formatter.format('one','two','three','four'))
print(formatter.format(True,False,False,False))
print(formatter.format(formatter,formatter,formatter,formatter))
print(formatter.format( "Try your","Own text here","Maybe a poem","Or a song about fear"))
		

Exercise 7

days = "Mon Tue Wed Thu Fri Sat Sun"
months = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\naug\n"

print("""There's something going on here .
With the three double-quotes.
We'll be able to type as much as we like.
Even 4 lines if we want, or 5 ,or 6""")

Exercise 8

escape

tabby_cat = "\tI'm tabbed in."
persian_cat = "I'm split \non a line."
backslash_cat = "I'm \\a\\cat."
fat_cat = """|
I'll do a list:
\t* Cat food
\t* Fishies
\t*Catnip\n\t*Grass
"""
print(tabby_cat)
print(persian_cat)
print(backslash_cat)
print(fat_cat)

Exercise 4

print("How old are you?", end = " ")
age  = input()
print("How tall are you?",end = ' ')
height = input()
print('How much do you weight?", end = ' ')
weight = input()
print(f"So, you're {age} old, {height} tall and {weight} heavy")

进阶

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

猜你喜欢

转载自blog.csdn.net/weixin_43702920/article/details/96361962