Skip to content

Commit c6406e8

Browse files
authored
test of local function import
1 parent c0d6444 commit c6406e8

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

Tasks/WK4Scratch.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##
2+
##
3+
4+
import helpers as h
5+
6+
val1 = h.get_int("Enter Value")

Tasks/helpers.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
## function to get an integer with error checking
3+
def get_int(input_prompt, min_val=int(1), max_val=int(100)):
4+
return_value=int(0)
5+
int_val=int(-1)
6+
7+
try:
8+
while not ((int_val >= min_val and int_val <= max_val)) :
9+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
10+
int_val=int(get_val)
11+
12+
## exit if select 0
13+
if int_val==0:
14+
break
15+
16+
return_value=int_val
17+
except:
18+
print ( f"Invalid '{input_prompt}' value entered '" + get_val + "'" )
19+
finally:
20+
return return_value
21+
22+
23+
## function to get a float with error checking
24+
def get_float(input_prompt, min_val=float(0.01), max_val=float(100.00)):
25+
return_value=float(0.0)
26+
float_val=float(-1)
27+
28+
try:
29+
while not ((float_val >= min_val and float_val <= max_val)) :
30+
get_val=input(input_prompt + f" (Min: {str(min_val)} Max: {str(max_val)} Exit: 0)")
31+
float_val=float(get_val)
32+
33+
## exit if select 0
34+
if float_val==0:
35+
break
36+
37+
return_value=float_val
38+
except:
39+
print ( f"Invalid '{input_prompt}' value entered '{get_val}'" )
40+
finally:
41+
return return_value
42+
43+
## function to get an Y/N with error checking
44+
def get_y_n ( input_prompt ):
45+
return_value=""
46+
var_val = "Z"
47+
48+
try:
49+
while not ( var_val == "Y" or var_val == "N" ) :
50+
var_val=input(input_prompt + f" (Y/N) ").upper()
51+
52+
## exit if select 0
53+
if var_val=='':
54+
break
55+
56+
return_value=var_val
57+
except:
58+
print ( f"Invalid '{input_prompt}' value entered '" + var_val + "'" )
59+
finally:
60+
return return_value
61+

0 commit comments

Comments
 (0)