forked from dathere/qsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_helper.py
30 lines (27 loc) · 900 Bytes
/
user_helper.py
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
# example python helper file that can be used with the py command
# qsv map --helper user_helper.py fib qsv_uh.fibonacci(num_col) data.csv
# qsv map --helper user_helper.py fahrenheit qsv_uh.celsius_to_fahrenheit(celsius) data.csv
def fibonacci(input):
try:
float(input)
except ValueError:
return "incorrect input - not a number"
sinput = str(input)
if not float(sinput).is_integer():
return "incorrect input - not a whole number"
n = int(sinput)
if n < 0:
return "incorrect input - negative number"
elif n == 0:
return 0
elif n == 1 or n == 2:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
def celsius_to_fahrenheit(celsius):
try:
float(celsius)
except ValueError:
return "incorrect input - not a float"
fahrenheit = (float(celsius) * 9/5) + 32
return f'{fahrenheit:.1f}'