def is_integer_string(s):
if not s.isdigit() and s[0]!='-':
return False
return int(s)==s
def print_hourglass(n,sym):
i=1
while n>=i**2:
print(''*(i-1)+sym*i*2)
print(''*(i-1)+sym*(i+1)*2)
i+=2
while i>0:
print(''*(i-1)+sym*i*2)
i-=2
print(n-i**2)
n=is_integer_string(input())
try:
n,sym=map(int,input().split())
except ValueError:
print("请输入一个数字")
print(print_hourglass(n,sym))
这串代码后
Traceback (most recent call last):
File "/tmp/a.py", line 20, in <module>
print(print_hourglass(n,sym))
NameError: name 'sym' is not defined. Did you mean: 'sum'?
这个sym的变量我该怎么修改
没搞明白要干啥, 盲猜写法