【发布时间】:2017-10-09 01:34:27
【问题描述】:
由于某种原因,我在整个作业中遇到了问题。
我们需要编写一个程序来查找 UPC 代码中的校验位。
我被难住了,所以这就是我到目前为止所拥有的......
def Find_UPC():
upc = str(input("What is the UPC?"))
odd = upc[0:11:2]
even = upc[1:12:2]
oddSum = sum(map(int, odd)) * 3
evenSum = sum(map(int, even))
total = oddSum + evenSum
mod = total % 10
if mod != 0:
check = 10 - mod
else:
check = mod
print("Your check didget is: "(check))
Find_UPC()
这是我的错误:
Traceback (most recent call last):
File "C:/Users/THOR/Desktop/Python/week 4/findUPC.py", line 22, in <module>
Find_UPC()
File "C:/Users/THOR/Desktop/Python/week 4/findUPC.py", line 20, in Find_UPC
print("Your check didget is: "(check))
TypeError: 'str' object is not callable
任何帮助将不胜感激!
【问题讨论】:
-
你可以用 print("Your check didget is: %s " % check) 改变你的打印
-
print("Your check didget is:", check) -
PS 数字拼写为“digit”。
标签: python