习题1-9.md

#笨办法学Python习题1-9

#print输出
print("hello world")
print("hello python")
print("i like typing this")
print("this is fun")

hello world
hello python
i like typing this
this is fun
#简单数值计算
print("25+30/6=",25+30/6)
print(25*2+23)
print(3+2<7-5)
25+30/6= 30.0
73
False
#变量和命名
cars=100
space_in_a_car=4.0
drivers=30
passenagers=90
cars_not_driven=cars-drivers
cars_driven=drivers
carpool_capacity=cars_driven*space_in_a_car
average_passenagers_per_car=passenagers/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,"peple today")
print("We have",passenagers,"to carpool today")
print("We need to put about",average_passenagers_per_car,"in each car")
There are 100 cars available
There are only 30 drivers available
There will be 70 empty cars today
We can transport 120.0 peple today
We have 90 to carpool today
We need to put about 3.0 in each car
#简单字符串
my_name='DMU.lzq'
my_age=23
my_height=175.3
my_weight=120
my_eye='black'
my_hair='black'

print("let`s talk about %s"% my_name) 
print("he is %d cm tall"%my_height)
print("he is %d kg heavy"%my_weight)
print("he is got %s eyes and %s hair."%(my_eye,my_hair))
print("if i add %d,%d,and %d,i will get %d"%(my_height,my_weight,my_age,my_height+my_weight+my_age))
let`s talk about DMU.lzq
he is 175 cm tall
he is 120 kg heavy
he is got black eyes and black hair.
if i add 175,120,and 23,i will get 318
#字符串和文本
x="There are %d tpye of people"%10
binary="binary"
do_not="dont"
y="Those who know %s and those who %s"%(binary,do_not)

print(x)
print(y)

print("I said:%r"%x)
print("I also said:'%s'"%y)

hilarious=False
joke_evaluation="Isnt that joke so funnny?!%r"

print(joke_evaluation%hilarious)

w="This is the left side of..."
e="a string with a right side."

print(w+e)
There are 10 tpye of people
Those who know binary and those who dont
I said:'There are 10 tpye of people'
I also said:'Those who know binary and those who dont'
Isnt that joke so funnny?!False
This is the left side of...a string with a right side.
#print练习
print("Mary had a little lamb.")
print("Its fleece was white as %s."%"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"

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


formatter="%r %r %r %r"
print(formatter%(1,2,3,4))
print(formatter%("one","two","three","four"))
print(formatter%(True,True,False,True))
print(formatter%(formatter,formatter,formatter,formatter))


days="Mon Tue Wed Thu Fri Sat Sun"
months="\nJan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug"

print("Here are the days:",days)
print("Here are the months:",months)
Mary had a little lamb.
Its fleece was white as snow.
And everywhere that Mary went
..........
Cheese
Burger
1 2 3 4
'one' 'two' 'three' 'four'
True True False True
'%r %r %r %r' '%r %r %r %r' '%r %r %r %r' '%r %r %r %r'
Here are the days: Mon Tue Wed Thu Fri Sat Sun
Here are the months: 
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug

猜你喜欢

转载自blog.csdn.net/DMU_lzq1996/article/details/82762476
md1