List value assignment
NoR3gr3t (1)

I'm trying to write a code that will accept up to three sets of name inputs and then switch from first last to last first format. Whenever the code is run if assigning more than one name it will remove the assignment for the previous names. I have six days to finish this.
import sys
namesInput = 0
enteringNames = True
while(namesInput < 3 and enteringNames == True):

fname = ['','','']
lname = ['','','']
fname[int(0 + int(namesInput))] = str(input("Input a first name.\n"))
lname[int(0 + int(namesInput))] = str(input("Input a last name.\n"))
namesInput = namesInput + 1
print('Would you like to input another name? You have input ' + str(namesInput) + ' so far.\nYes(1) or No(2)')
answer = int(input())
if(answer == 2):
enteringNames = False
while(namesInput > 2 or enteringNames == False):
if(namesInput == 1):
print('Your swapped name is:\n' + lname[0] + ', ' + fname[0])
if(namesInput == 2):
print('Your swapped names are:\n' + lname[0] + ', ' + fname[0] + '\n' + lname[1] + ', ' + fname[1])
if(namesInput == 3):
print('Your swapped names are:\n' + lname[0] + ', ' + fname[0] + '\n' + lname[1] + ', ' + fname[1] + '\n' + lname[2] + ', ' + fname[2])
break

You are viewing a single comment. View All
heyitsmarcus (287)

Why not just use a function that you can call over and over again? And instead of using fname[...] to identify the index, just use fname.append() to append the input to the fname variable? You're already controlling the flow with your namesInput counter variable.

I can't hand you the solution, because you'll learn nothing that way, but if you have questions, myself and others will be glad to help!

NoR3gr3t (1)

@heyitsmarcus I figured it out. I was resetting it to be blank every time the while loop ran.... face into desk

heyitsmarcus (287)

@NoR3gr3t Ah! awesome! I'm glad you figured it out. Happy Coding! =]

ash15khng (393)

@NoR3gr3t It's okay, we all have these moments