我试图编写一段代码来制作数字字典。这是代码:
inp = input('name of file?\n')
x = input('starting number?\n')
y = input('ending number?\n')
dic = open(inp, 'w')
while x <= y:
dic.write(x)
x += 1
一旦我运行它:
user@babas:~/script$ python3 numgen.py
name of file?
test file
starting number?
1
ending number?
9
Traceback (most recent call last):
File "numgen.py", line 12, in <module>
x += 1
TypeError: Can't convert 'int' object to str implicitly
我尝试在Google上寻找一些答案,但无法解决任何问题。