Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Nested Loop Problem

$
0
0
Well I am having a problem with the condition loops, since I nested loop apparently I would need two nested loops in order to make sure that I would be able to find the ratios inside of an array.

userinput, num1, store_ratios, count = [], 0, [], 0


count = int(input("How many numbers would you like to enter?"))

for i in range (0,count+1):
    num1 = int(input("Enter a number:"))
    userinput.append(num1)
for j in range (count+1, 0, -1):
    ratio = userinput[i]/userinput[j]
    store_ratios.append(ratio)
    print (store_ratios)



The problem I am having is with the nested loop and trying to find the ratio from the last one to the first one. For example:

ratio list = []
array_list = [3, 6, 12, 24, 48, 96]

Take the last array and divide the second last array and store in another array:

ratio = array_list[5]/array_list[4]

ratio_list.append(ratio)

So any ideas, that you could help me to fix the nested loop?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>