这个程序应该根据用户通过input()
方法指定的rows
和{
numRows = input('Please enter the number of rows: ')
numRows = eval(numRows)
numAst = input('Please enter the number of asterisks in a row: ')
numAst = eval(numAst)
for i in range(numRows):
print(numAst*'*')
我怀疑你在Python2下运行程序
这会给你
试着用Python3跑步
注意:像这样使用
eval
是危险的。为什么不改用int
?在如果你需要Python2版本。将}替换为{}
^{pr2}$input
替换为raw_input
,将{它在我的机器上运行,确保你在评估中传递字符串。 在这里检查http://docs.python.org/library/functions.html#eval
相关问题 更多 >
编程相关推荐