我正在尝试创建一个代码来计算两种不同产品尺寸之间的更好值
(例如,10 克黄油块 10 美元,或 20 克黄油块 15 美元)
目前,我只知道如何收集信息,但我不知道如何显示哪些项目与其他产品具有更高的价值、更差的价值或同等价值。到目前为止,这是我的代码:
a = int(input('Cost of first product($): '))
b = int(input('Cost of second product($): '))
c = int(input('Mass of first product(grams): '))
d = int(input('Mass of second product(grams): '))
提前致谢!
这是将显示结果的代码的最后一部分:
s = (a/c)
r = (b/d)
if (s>r):
print('Product two is better value at', r,'$/g.')
elif (s<r):
print('Product one is better value at', s,'$/g.')
else:
print('These products are the same value.')
所以,总的来说,你的代码应该看起来像这样:
a = int(input('Cost of first product($): '))
b = int(input('Cost of second product($): '))
c = int(input('Mass of first product(grams): '))
d = int(input('Mass of second product(grams): '))
s = (a/c)
r = (b/d)
if (s>r):
print('Product two is better value at', r,'$/g.')
elif (s<r):
print('Product one is better value at', s,'$/g.')
else:
print('These products are the same value.')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句