[Solved] How to loop an if statement with different values? [closed]


I was able to figure out something a little bit less messy by using an array, probably still not the best way of doing it but it’s the best that I could come up with.

length_of_charts = int(input("Enter how many songs you have in each of your weekly charts: "))
lengths = [3, 5, 10, 20, 40, 75, 100]

i = 0
weeks_in_range = {"Weeks at #1": [0, "Consecutive"]}
while length_of_charts > lengths[i]:
    weeks_in_range["Weeks in Top " + str(lengths[i])] = [0, "Consecutive"]
    i = i + 1
if length_of_charts > 1:
    weeks_in_range["Weeks in Top " + str(length_of_charts)] = [0, "Consecutive"]
song_charts = driver1.find_elements_by_xpath(song_charts_path)
#finds all of the charts that the song is on
song_chart_runs = [[None for i in range(2)] for j in range(len(song_charts))]
for i, song_chart in enumerate(song_charts):
    j = 0
    song_chart_runs[i][0] = int(song_chart.get_attribute("innerHTML").split("""<span class="history-position">""")[1].split("</span>")[0])
    #variable will be assigned as the song's chart position on that week
    song_chart_runs[i][1] = datetime.strptime(song_chart.get_attribute("innerHTML").split("</span></a></span>")[0].split(">")[-1], '%B %d, %Y')
    #variable will be assigned as the date of the chart
    if song_chart_runs[i][0] == 1:
        weeks_in_range["Weeks at #1"][0] = weeks_in_range["Weeks at #1"][0] + 1
        if i > 0 and weeks_in_range["Weeks at #1"][0] > 1 and (song_chart_runs[i-1][0] != 1 or song_chart_runs[i-1][1] + timedelta(days=7) != song_chart_runs[i][1]):
            weeks_in_range["Weeks at #1"][1] = "Non-Consecutive"
    while length_of_charts > lengths[j]:
        if song_chart_runs[i][0] <= length_of_charts and song_chart_runs[i][0] <= lengths[j]:
            weeks_in_range["Weeks in Top " + str(lengths[j])][0] = weeks_in_range["Weeks in Top " + str(lengths[j])][0] + 1
            if i > 0 and weeks_in_range["Weeks in Top " + str(lengths[j])][0] > 1 and (song_chart_runs[i-1][0] > lengths[j] or song_chart_runs[i-1][1] + timedelta(days=7) != song_chart_runs[i][1]):
                weeks_in_range["Weeks in Top " + str(lengths[j])][1] = "Non-Consecutive"
        j = j + 1
    if song_chart_runs[i][0] <= length_of_charts and length_of_charts != 1:
        weeks_in_range["Weeks in Top " + str(length_of_charts)][0] = weeks_in_range["Weeks in Top " + str(length_of_charts)][0] + 1
        if i > 0 and weeks_in_range["Weeks in Top " + str(length_of_charts)][0] > 1 and (song_chart_runs[i-1][0] > length_of_charts or song_chart_runs[i-1][1] + timedelta(days=7) != song_chart_runs[i][1]):
            weeks_in_range["Weeks in Top " + str(length_of_charts)][1] = "Non-Consecutive"

solved How to loop an if statement with different values? [closed]