当我尝试print在Python中使用语句时,它给了我这个错误:
>>> print "Hello, World!"
File "<stdin>", line 1
print "Hello, World!"
^
SyntaxError: Missing parentheses in call to 'print'
Run Code Online (Sandbox Code Playgroud)
那是什么意思?
为什么在Python 3中打印字符串时会收到语法错误?
>>> print "hello World"
File "<stdin>", line 1
print "hello World"
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud) 我在这段代码的输出中得到了很多小数(华氏温度到摄氏温度转换器).
我的代码目前看起来像这样:
def main():
printC(formeln(typeHere()))
def typeHere():
global Fahrenheit
try:
Fahrenheit = int(raw_input("Hi! Enter Fahrenheit value, and get it in Celsius!\n"))
except ValueError:
print "\nYour insertion was not a digit!"
print "We've put your Fahrenheit value to 50!"
Fahrenheit = 50
return Fahrenheit
def formeln(c):
Celsius = (Fahrenheit - 32.00) * 5.00/9.00
return Celsius
def printC(answer):
answer = str(answer)
print "\nYour Celsius value is " + answer + " C.\n"
main()
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如何使程序围绕小数点后两位的每个答案?
假设我有8.8333333333333339,我想将其转换为8.84.我怎样才能在Python中实现这一目标?
round(8.8333333333333339, 2)给予8.83而不是8.84.我是Python新手或一般编程人员.
我不想将其打印为字符串,结果将进一步使用.有关该问题的更多信息,请查看Tim Wilson的Python编程技巧:贷款和付款计算器.
我需要将货币金额计算为0.25,0.50,0.75,如果大于0.75,则必须舍入到下一个整数.
怎么做?
示例需要舍入:
等等.