python-3.数字运算,变量,格式化输出

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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SHUIPING_YANG

你的鼓励是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值