我收到以下错误
ValueError:无法将字符串转换为float:'asdf \ n'
来自此代码:
import sys
print('Hello, this is a short quiz. Please tell me your name')
name = int(sys.stdin.readline())
print('Are you ready %s?' % (name))
答案 0 :(得分:4)
除非您的名字是“7”,否则该代码将失败。您正在将输入字符串转换为int
。尝试:
name = sys.stdin.readline().strip()