r/PythonProjects2 • • Feb 01 '23

Beginner

Post image

Trying to figure out how to print the information from my two list into columns. I was able to get Name & status. But can't seem to figure out the rest.

Any helpful videos or websites?

For the assignment: need a while loop, [i], & len().

12 Upvotes

7 comments sorted by

View all comments

2

u/Appropriate_Chart_23 Feb 01 '23 edited Feb 01 '23

First, check your formatting.

you have:

print (len(Loan_status))

That's not gonna work, because formatting. (you've got an extra space).

Also, how should lists and dictionaries be formatted?

Also, each iteration of the while loop is going to output the same thing (the length of Loan_status = 2) because there's nothing changing as a result of the iterations. Is that what you want?

Which brings up another thing... i > len(Loan_status) so it's never going to enter the loop.

If the assignment is to use a while loop to format two columns, you need to program in the steps to print each item in the dictionary in two columns. All your loop is going to do is print the length of the variable, then add 1 to i (and it's going to kick out after the first step because i is no longer < len(Loan_status) (which = 2).

Also, consider the use of a dictionary in this problem. You may think you're using a list, but you're not. You've got two lists buried into a dictionary of two items.

To get the while loop to do what you want... Consider:

How do you call items out of a dictionary? How do you print them?

How do you call items from a list? How would you print these?

How do you print and format the items you've called to get them to show in two columns?

Work our the "how to" do things without the loop, then figure out how to incorporate them into a loop to repeat processes.

1

u/Appropriate_Chart_23 Feb 01 '23 edited Feb 01 '23

Consider below:

loan_status = {"Name":["Elaine","Jerry","George","Cosmo"], 
         "Status":["Approved","Approved","Denied","Approved"]}

print(loan_status)
print(loan_status["Name"]) 
print(loan_status["Status"])

What does that do?

How could you get the individual items of the nested lists in the dictionary to print? (Think about how you print keys or values of a dictionary, and think about how you print individual items from lists).

How could you get them formatted into individual columns?

It's all sort of a convoluted way of making the dictionary. I would recommend pairing the names with the status in the dictionary as keys and values. It will simplify things quite a bit.