In [1]:
def average1():
    n = int(input("How many numbers do you have? "))
    _sum = 0.0
    
    for i in range(n):
        x = float(input("Enter a number >> "))
        #_sum = _sum + x
        _sum += x
        
    print("\nThe average of the numbers is", _sum/n)
In [4]:
from random import randrange

def average2(n):
    _sum = 0.0
    
    for i in range(n):        
        x = randrange(n*10, n*20)
        print("x is ", x)
        _sum += x
        
    print("\nThe average of the numbers is", _sum/n)
In [5]:
average2(10)
x is  176
x is  123
x is  177
x is  186
x is  183
x is  100
x is  126
x is  149
x is  195
x is  103

The average of the numbers is 151.8
In [7]:
colors = ["red", "green", "blue", "purple"]
ratios = [0.2, 0.3, 0.1, 0.4]
list(zip(colors, ratios))
Out[7]:
[('red', 0.2), ('green', 0.3), ('blue', 0.1), ('purple', 0.4)]
In [8]:
for val in [('red', 0.2), ('green', 0.3), ('blue', 0.1), ('purple', 0.4)]:
    print(val)
('red', 0.2)
('green', 0.3)
('blue', 0.1)
('purple', 0.4)
In [9]:
for color, ratio in [('red', 0.2), ('green', 0.3), ('blue', 0.1), ('purple', 0.4)]:
    print(color, ratio)
red 0.2
green 0.3
blue 0.1
purple 0.4
In [10]:
colors = ["red", "green", "blue", "purple"]
ratios = [0.2, 0.3, 0.1, 0.4]
for color, ratio in zip(colors, ratios):
    print(color, ratio)
red 0.2
green 0.3
blue 0.1
purple 0.4
In [ ]: