exercise 3 数字运算 加减乘除,注意运算顺序 print ( "I will now count my chickens:" ) print ( "Hens" , 25 + 30 / 6 ) print ( "Roosters" , 100 - 25 * 3 * 4 ) print ( "Now I will cout the eggs:" ) print ( 3 + 2 + 1 - 5 + 4 % 2 - 1
exercise 3 数字运算
加减乘除,注意运算顺序
print("I will now count my chickens:")
print("Hens",25+30/6)
print("Roosters",100-25*3*4)
print("Now I will cout 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 less or equal?",5<=-2)
print(20.0+3.75)
print(10/0.1)
exercise 4 变量
左边变量名,右边值,字符串需要用单引号括起来
cars=100
space_in_a_car=4
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 availabe.")
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")
exercise 5 格式化输出
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(f"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 coffice.")
# 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}")
name='阳水平'
height=176 # cm
weight=60 # kg
hair='黑'
email='1037547965@qq.com'
print(f"我的名字叫做{name}")
print(f"我的身高是{height}cm")
print(f"我的体重是{weight}kg")
print(f"我的头发是{hair}色的")
print(f"我的邮箱是{email}")