from random import randrange

dimension = 7

# create u and v as empty list 
u = []
v = []

for i in range(dimension):
    u.append(randrange(-10,11)) # add a randomly picked number to the list u
    v.append(randrange(-10,11)) # add a randomly picked number to the list v

# print both lists
print("u is",u)
print("v is",v)

# let's create a result list 

# the first method
result=[]

# fill it with zeros
for i in range(dimension): 
    result.append(0)

print("result is initialized by the first method to ",result)

# the second method
# alternative and shorter solution for creating a list with zeros
result = [0] * 7 

print("result is initialized by the second method to",result)

# let's calculate 3u-2v
for i in range(dimension):
    result[i] = 3 * u[i] - 2 * v[i]

# print all lists
print("u is",u)
print("v is",v)
print("3u-2v is",result)

u = [1,-2,-4,2]

fouru=[4,-8,-16,8]

len_u = 0
len_fouru = 0
for i in range(len(u)):
    len_u = len_u + u[i]**2 # adding square of each value 
    len_fouru = len_fouru + fouru[i]**2 # adding sqaure of each value

len_u = len_u ** 0.5 # taking square root of the summation
len_fouru = len_fouru ** 0.5 # taking square root of the summation

# print the lengths
print("length of u is",len_u)
print("4 * length of u is",4 * len_u)
print("length of 4u is",len_fouru)

from random import randrange

u = [1,-2,-4,2]

print("u is",u)

r = randrange(9) # r is a number in {0,...,8}
r = r + 1 # r is a number in {1,...,9}
r = r/10 # r is a number in {1/10,...,9/10}

print()
print("r is",r)

newu=[]

for i in range(len(u)):
    newu.append(-1*r*u[i])

print()   
print("-ru is",newu)
print()

length = 0

for i in range(len(newu)):
    length = length + newu[i]**2 # adding square of each number
    print(newu[i],"->[square]->",newu[i]**2)
    
print()    
print("the summation of squares is",length)    
length = length**0.5 # taking square root
print("the length of",newu,"is",length)