|
|
发表于 2016-6-22 18:17:33
|
显示全部楼层
input(...)
input([prompt]) -> string
Read a string from standard input. The trailing newline is stripped.
If the user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError.
On Unix, GNU readline is used if enabled. The prompt string, if given,
is printed without a trailing newline before reading.
这个是python的解释,input是从标准输入中读取字符串。所以你要用int或者float强制转换一下。- string = input('')
- print(string)
- summ = 0
- try:
- float('abc')
- except ValueError:
- print('when error do')
- else:
- print('when no error do')
- for each in string:
- print(each)
- try:
- float(each)
- except ValueError:
- print('error')
- continue
- else:
- summ +=float(each)
- print(summ)
复制代码 你试试这样来做 |
评分
-
查看全部评分
|