0
How can I divide the numbers in a lisy by each other?
For example list = [10, 4, 2, 6] using a loop for? Could you write the loop, please? Thanksđ
3 Answers
+ 3
Empresa X ,
here is a sample how it can be done:
# we are iterating in both loops on the same list, but each loop has its own iterator.
# the output with print shows which numbers are taken and shows also the result
# to output only the result use this: print(divident / divisor)
lst = [10, 4, 2, 6]
for divisor in lst:
for divident in lst:
print(f" {divident} / {divisor} = {divident / divisor}")
# solution 1: in this solution all numbers will be divided by each other, also by itself. to prevent this, the code has to be modified slightly
+ 6
Empresa X ,
itg is your task to write the code. please do a try and share it here. if you get stuck we can support you.
thanks for your undestanding!
here is a hint:
we can use 2 nested for loops
+ 1
numbers = [4, 2, 6]
for x in numbers:
a = x /numbers[1]
numbers.pop(0)
numbers.pop(0)
b = a / numbers[0]
print(b)
At this point, I can't think of much else đ Lothar