# 数组中数据类型转换至int错误

m=int(input())

s=[]

a=0

while a!=1:

s.append(input().split())

a+=1

n=0

c=0

while(n<m):

q=s[n]

p=str(q)

if(p.isdigit()):

x=int(p)

else:

print(“notdefined”)

n+=1

if(x<0 or x>100):

print(“X”)

c+=1

if(x<60):

print(“E”)

if(60<=x<69):

print(“D”)

if(70<=x<79):

print(“C”)

if(80<=x<89):

print(“B”)

if(90<=x<=100):

print(“A”)

print(c)输入都是纯数字但是没法进行int转换。

``````>>> s
[['12', '21', '33']]
>>> q
['12', '21', '33']
>>> p
"['12', '21', '33']"
>>> p.isdigit()
False``````

Statement `x=int(p)` not executed, so you got `NameError: name 'x' is not defined` !

Replace `append` statement by method `+`.

``````    # s.append(input().split())
s += input().split()``````
``````>>> s
['12', '21', '33']
>>> q
'33'
>>> p
'33'
>>> p.isdigit()
True``````
2周前 评论
DonotCrazy （楼主） 2周前

``````>>> s
[['12', '21', '33']]
>>> q
['12', '21', '33']
>>> p
"['12', '21', '33']"
>>> p.isdigit()
False``````

Statement `x=int(p)` not executed, so you got `NameError: name 'x' is not defined` !

Replace `append` statement by method `+`.

``````    # s.append(input().split())
s += input().split()``````
``````>>> s
['12', '21', '33']
>>> q
'33'
>>> p
'33'
>>> p.isdigit()
True``````
2周前 评论
DonotCrazy （楼主） 2周前