这个作者一天净出幺蛾子.我这边还老打错字,我现在都不敢用缩写,都是全拼
str_vis_text = "013601267"
len_num = len(str_vis_text)
def run_text(num_t, text_about):
text_sum = 0
for i in range(0, num_t):
text_sum +=if_digit(text_about[i])*(i+1)
print(text_sum%11)
print(text_sum)
run_text(len_num, str_vis_text)
用excel计算的结果.
用python计算的结果
那么我直接把text_sum % 11变成运行代码不就成功了吗???
not all arguments converted during string formatting
差哪里呢??
天呐,我犯了一个问题
哈哈哈
应该是text_sum %11 可我写成了text_about % 11
修改后成功
def run_text(num_t, text_about):
text_sum = 0
for i in range(0, num_t):
text_sum += if_digit(text_about[i]) * (i + 1)
return text_sum % 11
a = str(run_text(len_num, str_vis_text))
print(str_vis_text + a)
结下来加个识别x的语句
最后成功的代码
def run_text(num_t, text_about):
text_sum = 0
for i in range(0, num_t):
text_sum += if_digit(text_about[i]) * (i + 1)
#这段代码不要放入到for循环里,注意缩紧
if text_sum % 11 == 10:
return "X"
else:
return text_sum % 11
a = str(run_text(len_num, str_vis_text))
print(str_vis_text + a)
str_vis_text = input("Enter the first 9 digits of an ISBN-10 as a string: ")
str_vis_text = "013601267"
str_vis_text = "013031997"
这3个名字大家自己选吧
忘了加if_digit的代码了
def if_digit(num):
if num == "0":
return 0
elif num == "1":
return 1
elif num == "2":
return 2
elif num == "3":
return 3
elif num == "4":
return 4
elif num == "5":
return 5
elif num == "6":
return 6
elif num == "7":
return 7
elif num == "8":
return 8
elif num == "8":
return 8
elif num == "9":
return 9