Reuse

Ethan
Ethan

Something I noticed about the validation stuff.

We're repeating code that's almost identical.

Could we use the same code? Write it once?

Good eye! Here are two lumps o' code.

  • service_level = ''
  • while service_level != 'g' and service_level != 'o' and service_level != 's':
  •     service_level = input('Service level (g=great, o=ok, s=sucked)? ')
  •     service_level = service_level.strip().lower()
  •     if service_level != 'g' and service_level != 'o' and service_level != 's:
  •         print('Please enter G, O, or S.')
  •  
  • smurfs = ''
  • while smurfs != 'y' and smurfs != 'n':
  •     smurfs = input('Are there Smurfs (Y/N)? ')
  •     smurfs = smurfs.strip().lower()
  •     if smurfs != 'y' and smurfs != 'n':
  •         print('Please enter Y or N.')

Not the same, but they have the same structure.

This module is about code reuse, key to productivity and cost reduction.