Note that there are some explanatory texts on larger screens.

plurals
  1. POperform different splits based off different criteria to create a distinct output
    primarykey
    data
    text
    <p>When I execute the below python code I have written, (I am trying to create a user name based off three distinct scenarios (1.user enters First, middle, and last name, 2. user enters first and last name, 3. user enters only last name. I am attempting to create a username based off the first 4 characters of the last name+first initial (when provided)+middle initial(when provided). When I execute the below code, using the first+last name combination or just last name, I receive </p> <blockquote> <pre><code>lastName = (listnames[2]) IndexError: list index out of range </code></pre> </blockquote> <pre><code>def entirename(fullName): lowername = str.lower(fullName) delimiter =' ' listnames = (lowername.split(delimiter)) lastName = (listnames[2]) lname = lastName[0:4] fInit = listnames[0] fname = fInit[0] mInit = listnames [1] mname = mInit[0] username =lname+fname+mname return def firstlast(fullName): lowername = str.lower(fullName) delimiter =' ' listnames = (lowername.split(delimiter)) lstName = (listnames[1]) lname = lastName[0:4] fInit = listnames[0] fname = fInit[0] username = lname+fname return def last(fullName): lowername = str.lower(fullName) delimiter =' ' listnames = (lowername.split(delimiter)) lstName2 = (listnames[0]) lname = lstName2[0:4] username = lname return def main(): print "Hello! This program will contruct a new userid for you." print "" fullName = raw_input('Please enter your full name: ') while True: if fullName[2]: entirename(fullName) break elif fullname[1]: firstlast(fullName) break elif fullname[0]: last(fullName) break main() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload