[Python Programming Basics to Advanced]: Calculations with for loop (p2) | Lab 10P-1

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 continue our discussion on for loop and will explore different calculation we can perform using the for loop. In this video we will see the sum and product calculation which we can do with for loop.

Complete Playlist:

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

Lab Manual 10 can be downloaded from here:

Review Questions:
Solve this series summation. Take the value of n from user and display the series sum:
1^2+2^2+3^2+4^2+…+n^2=∑k^2 (k:1→n)

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

Ans:

num=eval(input('Enter a number: '))
s=0
for i in range(1, num+1):
square=i**2 # Here we take square of every number
s+=square # Here we add all those squares.

print(f'Sum of series ∑k^2 (k:1→n) : {s}')

abdurrehmansarwar
Автор

x = 0
n = eval(input("Enter a number: "))
for i in range(1, n+1):
y = i**2
if (i==n):
print(f"{i}^2", end="=")
else:
print(f"{i}^2", end="+")
x += y
print(f"{x}")

hamidiftikhar
Автор

a=int(input("Enter a Number=: " ))
b= 0
for i in range(1, x+1):
b=b+(i**2)
print(b)

fourcloversan
Автор

x = int(input('Enter the number = '))
sum = 0
for i in range(1, x+1):
sum+=i**2
if i==x:
print(f'{i}^2', end='=')
else:
print(f'{i}^2', end='+')
print(sum)

aliraza-zlft
Автор

n=int(input('Enter a number:'))
s=0
for i in range(1, n+1):
s+=i**2
if i==n:
print(f'{i}^2', end='=')
else:
print(f'{i}^2', end='+')
print(s)

nukhbaiqbal
Автор

Ans :
num=eval(input("Enter the value of n: "))
sum=0
for i in range(1, num+1):
sum+=i**2
if(i==num):
print(f'{i}^2', end='=')
else:
print(f'{i}^2', end='+')
print(sum)

hamzaubaid
Автор

num=eval(input('Enter a number: '))
s=0
for i in range(1, num+1):
square=i**2 # Here we take square of every number
s+=square # Here we add all those squares.
if (i!=num):
print(f'{i}^2', end='+') # It display 1+2+ like this
else:
print(f'{i}^2', end='=') # it display 1+2+3=

print(s) # it gives our required result after equal 1+2+3=(result:14)

abdurrehmansarwar
Автор

Task)
X=int(input('Enter Number:'))
S=0
for i in range(1, X+1):
S=S+(i**2)
if (i==X):
print(f'{i}^2', end='=')
else:
print(f'{i}^2', end='+')
print(S)

hishamawan
Автор

a=0
b=eval(input("Enter a number:"))
for i in range(1, b+1):
x=i**2
if (i==b):
print(f"{i}^2", end="=")
else:
print(f"{i}^2", end="+")
s+=x
print(f"{a}", end=" ")

haris
Автор

x=eval(input('Enter a Numbe=:' ))
s= 0
for i in range(1, x+1):
m+=i**2
print(m)

muhammad-ahmad
Автор

n=eval(input("enter number: "))
s=0
for i in range(1, n+1):
s+=i**2
print(f'the series of summation is {s}')

talhakamboh
Автор

n=eval(input("enter any number:"))
s=0
for i in range(1, n+1):

s+=(i**2)

print(f"The series sum is-{s}")

dawood
Автор

REVIEW 1
n=int(input("Enter limiting number n :"))
sum=0
for a in range(1, n+1):
sum+=a**2
if a==n:
print(f'{a}^2', end="=" )
else:
print(f'{a}^2', end="+" )
print(sum)

MuhammadQasim-kwer
Автор

s = 0
n = eval(input('Enter number n: '))
for i in range(1, n+1):
s+=i**2
if (i==n):
print(i, end = '^2 =')
else:
print(i, end = '^2+')
print(s)

ahmedimran
Автор

Assalam-o-Alaikum sir,
n=10
s=0
for i in range(1, 1+n):
s+=i*2
print(s)

zainzakir
Автор

#Review Question
x=int(input('Enter a number: '))

s=0
for i in range(1, x+1):
s+=i**2
if (i==x):
print(f'{i}^2', end='=')
else:
print(f'{i}^2', end='+')
print(s)

akaabdullahmateen
Автор

Review Question:

x=int(input('Enter Number:'))

s=0
for i in range(1, x+1):
s=s+(i**2)
if (i==x):
print(f'{i}^2', end='=')
else:
print(f'{i}^2', end='+')

print(s)

abdul-hadi
Автор

s=0
n=eval(input("Enter a number:"))
for i in range(1, n+1):
x=i**2
if (i==n):
print(f"{i}^2", end="=")
else:
print(f"{i}^2", end="+")
s+=x
print(f"{s}", end=" ")

arslanrafiq
Автор

ReRun=''
while ReRun=='':
n=int(input('Enter a Positive integer: '))
s=0
for i in range(1, n+1):
s=s+(i**2)
print(s)
ReRun=input('Press Enter to Re-Run')

dotienv
Автор

a= 10
b= 0
for i in range(1, a+1):
b+=i**2
print(b)

ahmadlatif
welcome to shbcf.ru