MENU

Chapter 11 Conditional and Looping Constructs Solutions

Question - 51 : -
Write Python script to calculate sum of following series :
s = (1) + (1+2) + (1+2+3) +…+ (1+2+3+…+n)

Answer - 51 : -

sum 0
n = int (raw_input (“Enter the value of n :”)]
for a in range (2, n+2):
term = 0
for b in range (1,1):
term + = b
print “Term”, (a-1), “:”,term
sum + = term
print “Sum of”, n, “term is”, sum

Question - 52 : -
Write a Python program to check if a given number is an Armstrong number.

Answer - 52 : -

sum = 0
n = int (raw_input (“Enter number”)
n1 = n
while (n > 0):
a = n%10
sum = sum + (a * a * a)
n = n/10
if (sum ==n1):
print n, “is an Armstrong number”
else:
print n, “is not an Armstrong number”

Free - Previous Years Question Papers
Any questions? Ask us!
×