+ 2
Is there a way in Python to do something to every single output?
I want to round off every number in the output of this program to 4 decimal places https://code.sololearn.com/cBMDxew781Hr/?ref=app Is there an easy way to do that without manually putting round() in every line?
8 odpowiedzi
+ 10
could you ellaborate well cuz from your code you used round() in only two lines of code where else did you want to apply it..!?
+ 10
in your case you have to put it on every line then you have to put it in every line
+ 10
yes you can using the if..else statement but in the case of returning only one or two outputs
+ 4
good idea HonFu. Thank you!
+ 3
To every line which converts to another unit.
+ 3
Is there a way to do it in coee without doing it manually?
+ 3
how?
+ 3
How about writing a function?
Your output seems to follow the same pattern: First there is some calculation, then there is a string addendum.
def myformat (calculation,
addendum):
print(str(round(calculation,
4)) + addendum)