Need assistance

Rick Johnson rantingrickjohnson at gmail.com
Sun Jul 19 20:21:00 EDT 2015


On Sunday, July 19, 2015 at 6:07:14 PM UTC-5, craig... at gmail.com wrote: 
> def main():
>     name= input('Enter your full name: ')
>     split=name.split()
>     Full_name=split[2],split[0], split[1]
>     print(Full_name[2],',', Full_name[0], Full_name[1])
>     
> main()

Sorry, but this code is no where near done yet. What happens
when the user enters invalid input? *BANG*
        
> split=name.split()

Unpacking those variables would be wiser, and syntactically
cleaner, than storing them behind a single variable. And 
split is a horrible symbol choice. first, middle, and last 
would be more descriptive.

> Full_name=split[2],split[0], split[1]
> print(Full_name[2],',', Full_name[0], Full_name[1])

Yuck. Too noisy. Always try to keep indexing to a minimum.
And never, ever, repeat yourself.

    VALIDATE_YOUR_INPUT + REMOVE_THE_NOISE = A+
    
    EXTRA_CREDIT: Repeatedly ask for input until validation passes.

    EXTRA_EXTRA_CREDIT: Allow clean exit if the user declines input.



More information about the Python-list mailing list