为什么在输入int后下面的代码卡住了。或str升华文字?相同的代码可以在python3命令行或pycharm上正常运行。
print ('\n asks for an integer and prints the square of it\n')
def square(num):
return num **2
def ask():
while True:
try:
usr_input = int(input('Input an integer:'))
except:
print (f'An error occurred! Please try again!')
continue
else:
return (f'Thank you, your number squared is:{square(usr_input)}')
print(ask())
答案 0 :(得分:-1)
return (f'Thank you, your number squared is:',square(usr_input))
print(ask())
您需要使用平方函数。 希望对您有所帮助。
答案 1 :(得分:-1)
这是您的代码 只需做一下 square(usr_input))并删除花括号
print ('\n asks for an integer and prints the square of it\n')
def square(num):
return num ** 2
def ask():
while True:
try:
usr_input = int(input('Input an integer:'))
except:
print ('An error occurred! Please try again!')
continue
else:
return ('Thank you, your number squared is:',square(usr_input))
print(ask())
输出-
asks for an integer and prints the square of it
Input an integer:5
('Thank you, your number squared is:', 25)