[英]unexpected print output in python 3
I'm doing a python 3 tutorial and i'm trying to figure out where in my output these parentheses are coming from. 我正在做一个python 3教程,我试图弄清楚这些括号从哪里来。
students = int (input())
total = dict()
for i in range(0,students):
tokens = input().split()
name = tokens[0]
total[name] = float(tokens[1]) + float(tokens[2]) + float(tokens[3])
student = input(())
print ("{0:.2f}".format(total[student] / 3))
Expected Output 预期产量
56.00
My Output 我的输出
()56.00
replace this: 替换为:
student = input(())
with: 与:
student = input()
This is what happening : 这是正在发生的事情:
>>> student = input(())
()
In student = input(())
you are passing an empty tuple as the prompt argument to the input
function. 在student = input(())
您将传递一个空元组作为input
函数的提示参数。 Normally, you pass input
a prompt string , however input
(and raw_input
in Python 2) will happily accept any object for the prompt and convert it to a string, just like print
does. 通常,您向input
传递提示字符串 ,但是input
(和Python 2中的raw_input
)将很乐意接受提示的任何对象并将其转换为字符串,就像print
一样。 If no prompt is supplied then no prompt gets printed. 如果没有提供提示,则不会打印任何提示。 (I suspect that input
simply passes the prompt to print
). (我怀疑 input
只是通过提示进行print
)。
So your unexpected ()
is simply that empty tuple, converted to a string. 因此,您意外的()
只是将空元组转换为字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.