Help with these while loops and for loops


#1

a = [‘Alabama’,‘Alaska’,‘Arizona’,‘Arkansas’,‘California’,‘Colorado’]
b = [‘Connecticut’,‘Delaware’,‘Florida’,‘Georgia’,‘Hawaii’,‘Idaho’,‘Illinois’]
c = [‘Indiana’,‘Iowa’,‘Kansas’,‘Kentucky’,‘Louisiana’,‘Maine’,‘Maryland’]
d = [‘Massachusetts’,‘Michigan’,‘Minnesota’,‘Mississippi’,‘Missouri’]
e = [‘Montana’,‘Nebraska’,‘Nevada’,‘NewHampshire’,‘NewJersey’,‘NewMexico’]
f = [‘NewYork’, ‘NorthCarolina’, ‘NorthDakota’, ‘Ohio’,‘Oklahoma’,‘Oregon’]
g = [‘Pennsylvania’,‘RhodeIsland’,‘SouthCarolina’,‘SouthDakota’,‘Tennessee’]
h = [‘Texas’,‘Utah’,‘Vermont’,‘Virginia’,‘Washington’]
q = [‘WestVirginia’, ‘Wisconsin’,‘Wyoming’]

states = a + b + c + d + e + f + g + h + q

aa=[‘Montgomery’,‘Juneau’, ‘Phoenix’, ‘Little Rock’, ‘Sacramento’,‘Denver’]
bb=[‘Hartford’, ‘Dover’, ‘Tallahassee’, ‘Atlanta’, ‘Honolulu’,‘Boise’]
cc=[‘Springfield’, ‘Indianapolis’, ‘Des Moines’,‘Topeka’, ‘Frankfort’]
dd=[‘Baton Rouge’, ‘Augusta’, ‘Annapolis’, ‘Boston’, ‘Lansing’,‘St. Paul’]
ee=[‘Jackson’, ‘Jefferson City’, ‘Helena’,‘Lincoln’, ‘Carson City’, ‘Concord’]
ff=[‘Trenton’, ‘Santa Fe’, ‘Albany’, ‘Raleigh’, ‘Bismarck’, ‘Columbus’]
gg=[‘Oklahoma City’,‘Salem’,‘Harrisburg’, ‘Providence’, ‘Columbia’, ‘Pierre’]
hh=[‘Nashville’, ‘Austin’,‘Salt Lake City’, ‘Montpelier’,‘Richmond’]
mm=['Olympia ', ‘Charleston’, ‘Madison’, ‘Cheyenne’]

capitals = aa + bb + cc + dd + ee + ff + gg + hh + mm

#get a count for all the states that are longer than their capitals using while loops
#and print all the states that have the same second letter as their capitals Using while loops



#2

There is a difference between helping with the for loops and let someone else write the for loops for you

what is it you are struggling with in this process?


#3
n = 0
state_length = len(states[0])
capital_length = len(capitals[0])
count = 0
while n < len(states):
    if state_length < capital_length:
        n = n + 1
        count = count + 1
print(count)

im new to coding, but i tried this. its giving me all the states and capitals but no the specific ones. This is for the state which are longer that their capitals


#4

I must not be doing the process correctly


#5

n = 0
while n < len(states,capitals):
if states [n][1] == capitals [n][1]:
print(n)


#6

this might be closer but its still giving me errors


#7

please copy paste the data (all the lists) again with format:

it somehow ended up incorrect at the forum.


#8
a = ['Alabama','Alaska','Arizona','Arkansas','California','Colorado']
b = ['Connecticut','Delaware','Florida','Georgia','Hawaii','Idaho','Illinois']
c = ['Indiana','Iowa','Kansas','Kentucky','Louisiana','Maine','Maryland']
d = ['Massachusetts','Michigan','Minnesota','Mississippi','Missouri']
e = ['Montana','Nebraska','Nevada','NewHampshire','NewJersey','NewMexico']
f = ['NewYork', 'NorthCarolina', 'NorthDakota', 'Ohio','Oklahoma','Oregon']
g = ['Pennsylvania','RhodeIsland','SouthCarolina','SouthDakota','Tennessee']
h = ['Texas','Utah','Vermont','Virginia','Washington']
q = ['WestVirginia', 'Wisconsin','Wyoming'] 

states = a + b + c + d + e + f + g + h + q


aa=['Montgomery','Juneau', 'Phoenix', 'Little Rock', 'Sacramento','Denver']
bb=['Hartford', 'Dover', 'Tallahassee', 'Atlanta', 'Honolulu','Boise']
cc=['Springfield', 'Indianapolis', 'Des Moines','Topeka', 'Frankfort']
dd=['Baton Rouge', 'Augusta', 'Annapolis', 'Boston', 'Lansing','St. Paul'] 
ee=['Jackson', 'Jefferson City', 'Helena','Lincoln', 'Carson City', 'Concord'] 
ff=['Trenton', 'Santa Fe', 'Albany', 'Raleigh', 'Bismarck', 'Columbus'] 
gg=['Oklahoma City','Salem','Harrisburg', 'Providence', 'Columbia', 'Pierre'] 
hh=['Nashville', 'Austin','Salt Lake City', 'Montpelier','Richmond']
mm=['Olympia ', 'Charleston', 'Madison', 'Cheyenne'] 

capitals = aa + bb + cc + dd + ee + ff + gg + hh + mm

#9

list meaning this???


#10

‘n = 0
state_length = len(states[0])
capital_length = len(capitals[0])
count = 0
while n < len(states):
if len(captials[n] > len(states[n])
n = n + 1
count = count + 1
print(states[n],capitals[n])’


#11

‘n = 0
while n < len(states,capitals):
if states [n][1] == capitals [n][1]:
print(n)’


#12

‘’'
a = [‘Alabama’,‘Alaska’,‘Arizona’,‘Arkansas’,‘California’,‘Colorado’]
b = [‘Connecticut’,‘Delaware’,‘Florida’,‘Georgia’,‘Hawaii’,‘Idaho’,‘Illinois’]
c = [‘Indiana’,‘Iowa’,‘Kansas’,‘Kentucky’,‘Louisiana’,‘Maine’,‘Maryland’]
d = [‘Massachusetts’,‘Michigan’,‘Minnesota’,‘Mississippi’,‘Missouri’]
e = [‘Montana’,‘Nebraska’,‘Nevada’,‘NewHampshire’,‘NewJersey’,‘NewMexico’]
f = [‘NewYork’, ‘NorthCarolina’, ‘NorthDakota’, ‘Ohio’,‘Oklahoma’,‘Oregon’]
g = [‘Pennsylvania’,‘RhodeIsland’,‘SouthCarolina’,‘SouthDakota’,‘Tennessee’]
h = [‘Texas’,‘Utah’,‘Vermont’,‘Virginia’,‘Washington’]
q = [‘WestVirginia’, ‘Wisconsin’,‘Wyoming’]

states = a + b + c + d + e + f + g + h + q

aa=[‘Montgomery’,‘Juneau’, ‘Phoenix’, ‘Little Rock’, ‘Sacramento’,‘Denver’]
bb=[‘Hartford’, ‘Dover’, ‘Tallahassee’, ‘Atlanta’, ‘Honolulu’,‘Boise’]
cc=[‘Springfield’, ‘Indianapolis’, ‘Des Moines’,‘Topeka’, ‘Frankfort’]
dd=[‘Baton Rouge’, ‘Augusta’, ‘Annapolis’, ‘Boston’, ‘Lansing’,‘St. Paul’]
ee=[‘Jackson’, ‘Jefferson City’, ‘Helena’,‘Lincoln’, ‘Carson City’, ‘Concord’]
ff=[‘Trenton’, ‘Santa Fe’, ‘Albany’, ‘Raleigh’, ‘Bismarck’, ‘Columbus’]
gg=[‘Oklahoma City’,‘Salem’,‘Harrisburg’, ‘Providence’, ‘Columbia’, ‘Pierre’]
hh=[‘Nashville’, ‘Austin’,‘Salt Lake City’, ‘Montpelier’,‘Richmond’]
mm=['Olympia ', ‘Charleston’, ‘Madison’, ‘Cheyenne’]

capitals = aa + bb + cc + dd + ee + ff + gg + hh + mm
’’’


#13

i would make a variable named counter and give it a value of zero (or n is also fine)

now start the while loop, while counter is less then the length of states should be the condition

now get the current_state by accessing state list with index state_counter, and and current_capitol by accessing capitals list with index counter

you need to get the current_state and current_capitol within the loop, otherwise you are constantly comparing the first state and capitol with each other


#14

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.