import random

# 卖橘子的计算器:写一段代码,提示用户输入橘子的价格,
# 然后随机生成购买的斤数(5到10斤之间),最后计算出应该支付的金额!

# 第一种
# orange_price = input("请输入橘子的价格")
# #用于生成一个指定范围内的整数。其中参数a是下限,参数b是上限,生成的随机数n: a <= n <= b
# orange_catty = random.randint(5, 10)
# pay = int(orange_price) * orange_catty
# print("一共%d斤的橘子价格是%d¥/斤,应支付%d¥" % (orange_catty, int(orange_price), pay))

# 第二种
# orange_price = input("请输入橘子的价格")
# # 用于生成一个指定范围内的随机符点数,两个参数
# # 其中一个是上限,一个是下限。如果a > b,
# # 则生成的随机数n: a <= n <= b。如果 a <b, 则 b <= n <= a。
# orange_catty = round(random.uniform(5, 10), 2)
# pay = float(orange_price) * orange_catty
# print("一共%.2f斤的橘子价格是%.2f¥/斤,应支付%.2f¥" % (orange_catty, float(orange_price), pay))

# 第三种
# orange_price = input("请输入橘子的价格")
# # 从指定范围内,按指定基数递增的集合中 获取一个随机数。
# orange_catty = random.randrange(5, 10, 2)
# pay = int(orange_price) * orange_catty
# print("一共%d斤的橘子价格是%d¥/斤,应支付%d¥" % (orange_catty, int(orange_price), pay))

# 第四种
orange_price = input("请输入橘子的价格")
# 用于生成一个0到1的
# 随机浮点数:0<= n < 1.0
orange_catty = round(random.random(), 2)
pay = float(orange_price) * orange_catty
print("一共%.2f斤的橘子价格是%.2f¥/斤,应支付%.2f¥" % (orange_catty, float(orange_price), pay))
02-11 12:22