01_Python基础

hm_04qq号码

 

# 1.定义一个变量记录 QQ 号码
qq_number = "1234567"
# 2.定义一个变量记录 QQ 密码
qq_password = "123"

print(qq_number)
print(qq_password)

 

hm_05_超市买苹果

 

# 1.定义苹果单价
price = 8.5


# 2.挑选苹果
weight = 7.5


# 3.计算付款金额
money = weight * price

# 4.只要买苹果,就减去五块钱
money = money - 5

print(money)

 

hm_07_买苹果增强版

# 1.输入苹果的单价
price_str = input("苹果的单价")
# 2.输入苹果的重量
weight_str = input("苹果的重量")
# 3.计算支付的金额
# 注意:两个字符串变量之间不能直接用乘法
# money = price_str * weight_str
# 1>将价格转换成小数
price = float(price_str)
# 2>将重量转换成小数
weight =float(weight_str)
# 3>用两个小数来计算最终的金额
money = price * weight
print(money)

 

hm_08_买苹果改进

# 1.输入苹果的单价
price = float(input("苹果的单价"))
# 2.输入苹果的重量
weight = float(input("苹果的重量"))
# 3.计算支付的金额

money = price * weight
print(money)

 

hm_09_格式化输出

 

# 定义字符串变量 name, 输出 我的名字叫 小明,请多关照!
name = "意大利炮"
print("我的名字叫%s,请多关照!"% name)

# 定义整数变量 student_no, 输出 我的学号是 000001
student_no = 100123
print("我的学号是 %06d" % student_no)

#定义小数 pric weight money,
# 输出 苹果单价 9.00 元/斤,购买了 5.00 元/斤,需要支付 45.00 元
price = 8.5
weight = 7.5
money = price * weight
print("苹果单价 %.2f 元/斤,购买了 %.3f 元/斤,需要支付 %.4f 元" %(price,weight,money))

# 定义一个小数 scale, 输出的比例是 10.00%
scale = 0.9
print("输出的比例是 %.2f%%" % (scale * 100))

 

posted @ 2018-12-05 23:34  geittom  阅读(118)  评论(0)    收藏  举报