python习题教程 EP5

本文展示了一个Python程序示例,通过使用变量和格式化字符串进行打印操作,演示了如何在程序中显示个人的详细信息,包括姓名、年龄、身高、体重等,并计算这些变量的总和。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

习题5:更多变量与打印

程序代码:

name =  'Zed A. Shaw'
age = 35 # not a lie
height = 74 # inches
weight = 180 # lbs
eyes = 'Blue'
teeth = 'while'
hair = 'Brown'

print(f"Let's talk about {name}.")
print(f"He's {height} inches tall.")
print(f"He's {weight} poundc heavy.")
print("Actually that's not too heavy.")
print(f"he's got {eyes} eyes and {hair} hair.")
print(f"His teeeh are usually {teeth}")

# this line is tricky, try to get it exactly right
total = age + height + weight
print(f"If I add {age}, {height}, and {weight} I get {total}.")

应该看到的结果

Let's talk about Zed A. Shaw.
He's 74 inches tall.
He's 180 poundc heavy.
Actually that's not too heavy.
he's got Blue eyes and Brown hair.
His teeeh are usually while
If I add 35, 74, and 180 I get 289.

巩固练习

  1. 修改所有变量的名字,把它们前面的“my_”去掉
  2. 试着用变量将英寸和磅转换成厘米和千克
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值