python-3.数字运算,变量,格式化输出(python把数值换成字符)

网友投稿 280 2022-08-26


python-3.数字运算,变量,格式化输出(python把数值换成字符)

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=100space_in_a_car=4drivers=30passengers=90cars_not_driven=cars-driverscars_driven=driverscarpool_capacity=cars_driven*space_in_a_caraverage_passengers_per_car=passengers/cars_drivenprint("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 liemy_height = 74 # inchesmy_weight = 180 # lbsmy_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 righttotal = my_age + my_height + my_weightprint(f"If I add {my_age}, {my_height}, and {my_weight} I get {total}")name='阳水平'height=176 # cmweight=60 # kghair='黑'email='1037547965@qq.com'print(f"我的名字叫做{name}")print(f"我的身高是{height}cm")print(f"我的体重是{weight}kg")print(f"我的头发是{hair}色的")print(f"我的邮箱是{email}")


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:python-2.输出字符串,注释(python2注释怎么写)
下一篇:SpringBoot整合Mysql和Redis的详细过程
相关文章

 发表评论

暂时没有评论,来抢沙发吧~