-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatatool.py
More file actions
59 lines (41 loc) · 1.29 KB
/
datatool.py
File metadata and controls
59 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Test of several data precision libraries.
# Includes techniques discussed in several volumes:
# "Data Wrangling with Python"
from decimal import getcontext, Decimal
import logging
logging.warning('Test Warning #####')
a = .1
b = .204
print('\nRaw float addition without decimal library')
print(a+b)
print('\nFloat addition with decimal library')
getcontext().prec = 2 # changing precision does not modify this outcome
print(a+b)
# methods for data
# method for calculating volume
def vol(rad):
"Calculate the volume"
return(4.0/3)*3.14*(rad**3)
def inrange(num, low, high):
"Determine whether number is in the desired range"
if num in range(low, high):
print " %s is within the requested range" % str(num)
else:
print "The number is outside of the range."
# or just boolean check in range
def inrangeboolean(num, low, high):
return num in range(low, high)
def parseresults(s):
"Count the quantity of Upper and lowercase characters"
d = {"upper": 0, "lower": 0}
for c in s:
if c.isupper():
d["upper"] += 1
elif c.islower():
d["lower"] += 1
else:
pass
print "Original string: ", s
print "Uppercase characters: ", d["upper"]
print "Lowercase characters: ", d["lower"]
# -30-