0
Nach Funktion nicht funktioniert:Runde einen Schwimmer in einer Funktion
def myround(sfloat, dec):
print("{0:."+str(dec)+"f}") # only to show the string formed.
return ("{0:."+str(dec)+"f}".format(sfloat))
myround(2.35698, 2)
Der Fehler ist:
{:.2f}
Traceback (most recent call last):
File "mytest.py", line 8, in <module>
myround(2.35698, 2)
File "mytest.py", line 6, in myround
return ("{0:."+str(dec)+"f}".format(sfloat))
ValueError: Single '}' encountered in format string
Die erste Druckfunktion zeigt die richtige Zeichenfolge: {:.2f}
. Ich habe versucht {0:.2f}
, aber das funktioniert auch nicht. \{
und \}
funktionieren auch nicht.
Wo ist das Problem und wie kann es gelöst werden?
Es war so einfach. Vielen Dank. – rnso