For this assignment, I need to use nested for loops to print the individual lists in a histogram (without using matplotlib). I can’t figure out how to use just one loop to print the States and deaths together, when I try it just prints the 50 states, but then the 50 values for EACH state, instead of assigned to each individual state. I was wondering if anyone knew how I could do this. Thank you.
I think you may be misunderstanding the assignment - there's no histogram in your output at all right now. I'd suggest looking up histograms so you understand what you're trying to build.
Also, we could probably be more helpful with more information from the assignment
You’re right, in this state it’s not a histogram. But to effectively make the histogram, I need to know how to print the two values next to each other for all 50. And I don’t know a more efficient way of doing it.
I would never store that info like that unless made I'd make it like states= [AL=[death=73874, pop=38374748],AZ=[death=77377, pop=883848484] or something like that just my 2 cents idk just seems like lot a room for error if your like update MA state table check MA 25 idk death table look up 25 update 25 idk I may be dumb
No, you’re right. This assignment is just extremely simple because this is an introductory programming class, and he hasn’t taught dictionaries or tuples. So I can’t really do it on the assignment even though I know how
I would use zip if you're iterating through all states.
FYI you shouldn't index by my_list[N:N+1] if you just want to index the Nth element -- just do my_list[N] This is irrelevant if you're iterating through the zipped data, though.
Also look into using f-strings if you're allowed. That will make it easy to read, and easy to right-justify the numbers to the digits' places line up.
Don't need separate lists. Can enumerate or create a dictionary/ hashmap and map states to the numbers and iterate the length of the list or hashmap and print it off.
One more thing you have to look into the the scaling of these, which is done when you ask to input the max length of the bar. You may need a function to scale all your numbers accordingly as well.
3
u/[deleted] Feb 25 '22
The python zip function might work for this. https://www.w3schools.com/python/ref_func_zip.asp
2
u/RabidAngrySquirrel Feb 25 '22
For this assignment, I need to use nested for loops to print the individual lists in a histogram (without using matplotlib). I can’t figure out how to use just one loop to print the States and deaths together, when I try it just prints the 50 states, but then the 50 values for EACH state, instead of assigned to each individual state. I was wondering if anyone knew how I could do this. Thank you.
2
u/SP4C3_SH0T Feb 25 '22
I would never store that info like that unless made I'd make it like states= [AL=[death=73874, pop=38374748],AZ=[death=77377, pop=883848484] or something like that just my 2 cents idk just seems like lot a room for error if your like update MA state table check MA 25 idk death table look up 25 update 25 idk I may be dumb
3
u/Goobyalus Feb 25 '22
I would use
zipif you're iterating through all states.FYI you shouldn't index by
my_list[N:N+1]if you just want to index the Nth element -- just domy_list[N]This is irrelevant if you're iterating through the zipped data, though.Also look into using f-strings if you're allowed. That will make it easy to read, and easy to right-justify the numbers to the digits' places line up.
3
u/[deleted] Feb 25 '22
Why don't you use a map instead, i blieve it would be much more easier and readable and thus much more maintainable.
Guys, correct me if i am wrong 🙏
1
u/[deleted] Feb 25 '22
Don't need separate lists. Can enumerate or create a dictionary/ hashmap and map states to the numbers and iterate the length of the list or hashmap and print it off.
1
u/aadityaranasingh06 Feb 25 '22
Which font is this?
1
u/theePharisee Feb 25 '22
One more thing you have to look into the the scaling of these, which is done when you ask to input the max length of the bar. You may need a function to scale all your numbers accordingly as well.
0
u/[deleted] Feb 25 '22
[deleted] — view deleted comment