So I have been searching on Overflow for a few days now for a problem that I am working on. I understand the communities efforts to curb the homework questions, but I am stumped and would like to learn this concept and move on to learn more programming.
In Python I am developing a Matrices or 2D Array.
Here are the Array's Programming requirements from the user and comparing the value to the arrays value:
Then ask the user to enter both the first name and last name of one of the users in the matrix, then print the corresponding information (entire row) for that person if found; if not found, print 'User Not Found!'
Here's what I have so far on that array.
rows = 5
cols = 7
names_matrix = ([['lname', 'fname', 'city', 'state', 'zipcode'],
['Zdolfalos', 'Johnson', 'Terrell', 'Wilson', 'Key', 'Smith',
'Alfonso'],
['Fred', 'Malcom', 'Monkey', 'Wilson', 'LeDoor', 'Jim Bob', 'Ralph'],
['Charlotte', 'Monroe', 'Broken Pine', 'Hogwart', 'Spot in Road',
'Denver','Gastonia'],
['NC', 'NC', 'SC', 'VA', 'AL', 'NC', 'NC' ],
['28210', '28337', '28974', '27457', '36827', '28037', '28559'] ])
print names_matrix
#Create a Boolean variable flag.
found = False
#Create a variable to use as a loop counter.
index = 0
#Get the strings to search for.
for in names_matrix: #Having problems here with what goes here in For In Loop
userFirstName = raw_input('What is the user first name?')
userLastName = raw_input('What is the user last name?')
if userFirstName == names_matrix [1] and userLastName == names_matrix [0]:
print('')
#I want to print the Matrix value from the user input
else
print('User Not Found!')
# nested find columns
# https://stackoverflow.com/questions/7845165/how-to-take-input-in-an-array-python
I'm new to python and programming and have seen in the book how they made this with a While Loop with the false and index. I was having difficulty understand pass by values and references I think as well.
# Get the string to search for.
searchValue = raw_input('Enter a name to search for in the list: ')
# Step through the list searching for the
# specified name.
while found == False and index < len(names):
if names[index] == searchValue:
found = True
else:
index = index + 1
# Display the search results.
if found:
print 'That name was found in element ' + str(index + 1)
else:
print 'That name was not found in the list.'
I was wondering how to do this with a For In Range Loop. It might be a Nested Loop and those are a bit more tricky.
I don't believe I need the boolean flag or index part at the beginning of my coding for a For In range loop. I was just showing my progress so far and was trying to get this program to work better.
I researched the following helpful links for For In Range but was getting stumped.
Python If Else Nested Statements
We haven't gone over Class and Objects and did see how to do that, and we also haven't gone over numpy and tried using import numpy and was having some problems with that as I'm new to numpy as well. I am reading Think Like a CS with Python as additional help with the class as well as Learn Python the Hard Way.
Thanks for your time.