[Python Programming Basics to Advanced] : List in Python | Lab 16

preview_player
Показать описание
This Python programming playlist is designed to take beginners with zero programming experience to an expert level. The course covers installation, basic syntax, practical scenarios, and efficient logic building. The course material includes PDF handouts, review questions, and covers a wide range of topics, from data types to advanced functions like Lambda and Recursive functions, Generators, and JSON data parsing.

In this lesson we will learn about List in Python. A List can hold more than one objects. We can call those objects as elements of the list.
Each element in the list has an Index through which we can access that.

We will also learn how to process the complete list.

Complete Playlist:

If you have the basic programming knowledge and interested to learn Object-Oriented Programming in Python, check out this playlist:

Lab Manual 16 can be downloaded from here:

Review Questions:
Define two lists, a and b having same number of numeric values. Then your program should calculate and print the sum of the products of each corresponding element of the two lists i.e. elements in both lists at index 0 will get multiplied and so on till the last elements, and then should be sum of all these products.

#PythonProgramming #python #pythontutorial
Рекомендации по теме
Комментарии
Автор

x=[10, 20, 30, 40, 50]
y=[60, 70, 80, 90, 100]
p=1
s=0
for i in range(len(x)):
p=x[i]*y[i]
s+=p
print(f'The Suum of Products is {s}')

muhammad-ahmad
Автор

a=[2, 7, 12, 20, 38]
b=[3, 8, 13, 21, 39]
s=0
for i in range(len(a)):
s+=a[i]*b[i]
print(f"Sum of products of corresponding elements is '{s}'")

shaheerahmadkhan
Автор

a = [1, 2, 3, 4, 5]
b = [2, 4, 6, 8, 10]
s = 0
for i in range(len(a)):
s += (a[i]*b[i])
print(f'The sum of products is: {s}')

hamidiftikhar
Автор

Assalam-o-Alaikum Respected Sir:
#Review Question:
a=[1, 2, 3, 4, 5]
b=[6, 7, 8, 9, 10]
p=1
s=0
for i in range(len(a)):
p=a[i]*b[i]
s+=p
print(f'The sum of product is:{s})

zainzakir
Автор

a=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
b=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
S=0
for i in range (len(a)):
S+=(a[i]*b[i])
print(f'The sum of products of each corresponding element of two lists is: {S}')

habibaasif
Автор

a=[1, 2, 3, 4, 5]
b=[6, 7, 8, 9, 10]
p=1
s=0
for i in range(len(a)):
p=a[i]*b[i]
s+=p
print(f'The Sum of Products is {s}.')

usman_tariq
Автор

s=0
a=[1, 2, 3, 4]
b=[5, 6, 7, 8]
for i in range(len(a)):
x=(a[i]*b[i])
s+=x
print(f"The sum of the product of {a} and {b} = {s}")

rajahaseebahmad
Автор

2019-MC-13
A=[2, 6]
B=[6, 2]
S=0
for i in range(len(a)):
S+=A[i]*B[i]
print(f'The sum is {S}.')

dotienv
Автор

a = [6, 8, 7, 1]
b = [23, 24, 25, 26]
s = 0
c = a[0]*b[0], a[1]*b[1], a[2]*b[2], a[3]*b[3]
for i in c:
s+=i
print(f'The set of product is {c} and sum is {s}')

ahmedimran
Автор

Review question:
a=[4, 2, 6, 3, 7]
b=[8, 7, 10, 9, 5]
sum=0
for i in range (len(a)):
sum+=(a[i]*b[i])
print(f'The sum of product of both lists is {sum}.')

nukhbaiqbal
Автор

a=[2, 4, 6, 8, 10]
b=[1, 3, 5, 7, 9]
S=0
for i in range (len(a)):
S+=(a[i]*b[i])
print(f"Sum of products two lists is: {S}")

arslanrafiq
Автор

a=[1, 2, 3]
b=[4, 5, 9]
p=1
s=0
for i in range(len(a)):
p=a[i]*b[i]
s+=p
print(f'The Sum of Products is {s}.')

Fishy_gamedev_and_art
Автор

a=[1, 2, 3, 4, 5]
b=[6, 7, 8, 9, 10]
p=1
s=0
for i in range(len(a)):
p=a[i]*b[i]
s+=p
print(f'The sum of product is:{s})

AsadAli-tkvw
Автор

a=[1, 200, 2, 10, 2]
b=[100, 1, 2, 5, 3]
s=0
for i in range(len(a)):
x=a[i]*b[i]
s+=x
print(f"The sum of product = {s}")

yusrakashif
Автор

s=0
a=[2, 4, 6, 8, 10]
b=[1, 3, 5, 7, 11]
for i in range(len(b)):
s+=(a[i]*b[i])
print("Sum=", s)

amaanmajid
Автор

#ReviewQuestion
a=[23, 34, 89, 90]
b=[41, 22, 65, 97]
p=1
s=0
for i in range(len(b)):
p=a[i]*b[i]
s+=p
print(f'Sum of product of two lists is {s}')

irsaidress
Автор

a=[2, 3, 4, 5, 7, 89, 23, 1, 4, 234]
b=[23, 344, 254, 6, 78, 9, 0, 46, 231, 5]
s=0
p=1
for i in range(len(a)):
p=a[i]*b[i]
s+=p
print(f'The sum of the products of the corresponding enters is {s}.')

saifullahafzal
Автор

from random import randint

a = [randint(1, 1000) for i in range(100)]
b = [randint(1, 1000) for i in range(100)]
print(sum([a*b for a, b in zip(a, b)]))

muhammadshess
Автор

Ans:

a=[1, 4, 7, 2, 9]
b=[1, 3, 5, 6, 10]
S=0
for i in range (len(a)):
S+=(a[i]*b[i])
print(f"Sum of products two lists is: {S}")

hamzaubaid
Автор

a=[6, 0, 8, 3, 7]
b=[9, 4, 2, 1, 5]
y=0
for i in range(len(a)):
z=a[i]*b[i]
y+=z
print(f"Sum of all products is {y}")

MuhammadAhmad-dshu