Jun-08-2019, 04:24 PM
You have the same variable storing the text that is displayed when asking for input as the one that is storing the actual cable size.
as 'Please enter the cable size...:' will always be used inside of
It would also be good to let the user know what choices of cable size are available
as 'Please enter the cable size...:' will always be used inside of
get_valid_cable_size
you could remove the need to pass this in as a parameter.It would also be good to let the user know what choices of cable size are available
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
CABLES = ( 25 , 35 , 50 , 70 , 95 , 120 , 150 , 195 , 250 , 300 , 500 ) ... ... def get_valid_cable_size(): print ( 'Valid cable sizes are as follows:' ) print ( ', ' .join( map ( str , CABLES))) while True : cableSize = get_valid_input( 'Please enter the cable size...:' ) if cableSize in CABLES: return cableSize print ( 'Please enter a valid cable size' ) ... ... cableSize = get_valid_cable_size() print (cableSize) |
Output:Valid cable sizes are as follows:
25, 35, 50, 70, 95, 120, 150, 195, 250, 300, 500
Please enter the cable size...:21
Please enter a valid cable size
Please enter the cable size...:25
25.0