这里是我写的代码,请在最后一行下面找到回溯。Python代码中的数学问题。公式问题
kegsize = int(input('Please enter keg size. Litres: '))
costofkeg = int(input('Please enter cost of keg. GBP: '))
abv = input('Please enter Alcohol by Volume. %: ')
gp = int(input('Please enter Gross Profit Percentage. %: '))
opt = print('These are the Portion Size options (imperial measurements), 1/3, 1/2, 2/3, 1')
portionsize = input('Please choose Portion Size: ')
if portionsize not in ['1/3' , '1/2' , '2/3' , '1']:
print('Please enter a Portion Size from the list')
else:
print('Thank you')
print ('Keg Size', kegsize, 'Litres')
print ('Cost of Keg', costofkeg, 'GBP')
print ('Alcohol by Volume', abv, '%')
print ('Gross profit percentage', gp, '%')
GrossSp = (costofkeg/(kegsize/portionsize*0.568)/(1-gp))*1.2)
我似乎在过去遇到类似的错误,但无法找到我的任何代码,其中相同的回溯输出。请有人教我如何纠正这些错误。
Traceback (most recent call last):
File "C:/Users/Zico/Desktop/Papa, code.py", line 23, in <module>
GrossSp = (costofkeg/(kegsize/portionsize*0.568)/(1-gp))*1.2
TypeError: unsupported operand type(s) for /: 'int' and 'str'
'portionsize'是一个字符串...你需要将其转换就像你为别人'INT(输入() )'... –
对不起,我没有关注。如果没关系,你可以帮我做吗?谢谢! – user5701168
你的问题是'linesize = input('请选择部分大小:')'这需要是一个整数或浮点数 – dawg