|
发表于 2022-11-24 11:54:16
|
显示全部楼层
n =int(input("需要多少铅笔") )
x1=int(input("第一种铅笔的价钱"))
x2=int(input("第一种铅笔的个数"))
y1=int(input("第二种铅笔的价钱"))
y2=int(input("第二种铅笔的个数"))
z1=int(input("第三种铅笔的价钱"))
z2=int(input("第三种铅笔的个数"))
if n>x2:
if n%x2==0:
o1=(((n//x2))*x1)
else:
o1=(((n//x2)+1)*x1)
else:
o1=x1
if n>y2:
if n%y2==0:
o2=(((n//y2))*y1)
else:
o2=(((n//y2)+1)*y1)
else:
o2=y1
if n>z2:
if n%z2==0:
o3=(((n//z2))*z1)
else:
o3=(((n//z2)+1)*z1)
else:
o3=z1
if o1>o2 and o3>o2:
print(f"选择第二种,花费了{o2}块")
elif o1>o3 and o2>o3:
print(f"选择第一种,花费了{o3}块")
elif o2>o1 and o3>o1:
print(f"选择第一种,花费了{o1}块")
有点长 但这个是我第一个想到的方法了
|
|