【发布时间】:2018-01-08 16:16:17
【问题描述】:
这个 for 循环应该接受输入的输入并将字符转换为整数。
input = a
output = []
for char in input:
num = ord(char) - 96
output.append(num)
问题是最后输出等于“[1]”。
>>>print(output)
>>>[1]
我需要它是一个整数才能相乘。
【问题讨论】:
-
那为什么要把它附加到一个列表中呢?
-
为什么
output是一个列表开头? -
第一行应该是
input = "a"吗?顺便说一句,您不应该使用input作为变量名,因为这会影响内置的input函数。 -
到retrieve an item from a list,使用它的索引
n = output[0]。 -
你的输入是一个只包含数字的字符串吗?