We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b59b267 commit 5972a02Copy full SHA for 5972a02
newcodes/answers/q66.py
@@ -0,0 +1,23 @@
1
+#!/usr/bin/env python
2
+# coding=utf-8
3
+
4
+class RoundFloat(object): #Python 3: class RoundFloat:
5
+ def __init__(self, val):
6
+ assert isinstance(val, float), "value must be a float."
7
+ self.value = round(val, 2)
8
9
+ def __str__(self):
10
+ return "{:.2f}".format(self.value)
11
12
+ __repr__ = __str__
13
14
+if __name__ == "__main__":
15
+ while True:
16
+ n = input("Input a float:('q'-exit)")
17
+ if n == 'q':
18
+ print('See you next time.')
19
+ break
20
+ else:
21
+ n = float(n)
22
+ r = RoundFloat(n)
23
+ print(r)
0 commit comments