Exercise 5:
Step 1: Start the Program
Step 2: Initialize sum 0 and reads an integer number and store it in ‘num’.
Step 3: Loop until, it reaches the number given by user.
Step 4: Check whether the number is divisible by the iterated value, if it is true then add the iterated
value with ‘sum’ and store it in ‘sum’ and if it is false goto step 5.
Step 5: Repeat the steps 3 & 4, until the loop terminates.
Step 6: Check whether ‘sum’ is equal to ‘num’ then display that the given number is perfect. Else
display it is not the perfect number.
Step 7: Stop the program.
Exercise 6:
Step 1: Start the Program
Step 2: Take the number to be checked as input from the user as ‘num’ and initialize sum0.
Step 3: Determine the number of digits in the number, say it is n.
Step 4: Loop until n is greater than 0.
Step 5: Extract each digit from the number. Now raise each of these digits to the power n.
Step 6: Keep adding the nth power of these digits in the variable, ‘sum’.
Step 7: Repeat the steps 4 to 6, until the loop terminates.
Step 8: Check if the value of sum is equal to the number(num) itself. If both are equal, then the
number will be called as an Armstrong number, else it is not an Armstrong number.
Step 9: Stop the program.
Exercise 7:
Step 1: Start the Program
Step 2: Take the number to be checked as input from the user as ‘num’ and initialize reverse0.
Step 3: Determine the number of digits in the number, say it is n.
Step 4: Loop until n is greater than 0.
Step 5: Isolate the last digit of the number(n) and store it in ‘digit’. The modulo operator (%) returns
the remainder of a division
Step 6: Append ‘digit’ to reverse. reverse = (reverse * 10) + digit.
Step 7: Remove the last digit from the number. n = n / 10.
Step 8: Repeat the steps 4 to 7, until the loop terminates.
Step 8: Now we compare the reversed number with the original number(num). If the numbers are
the same, then the number is a palindrome, else it is not.
Step 9: Stop the program.
Exercise 8:
Step 1: Start the Program
Step 2: Initialize count 0 and reads an integer number and store it in ‘num’.
Step 3: Loop until, it reaches the number given by user.
Step 4: Check whether the number is divisible by the iterated value, if it is true then add 1 with
‘count’ and store it in ‘count’ and if it is false goto step 5.
Step 5: Repeat the steps 3 & 4, until the loop terminates.
Step 6: Check whether ‘count’ is greater than 2 then display “The given number is Composite”, check
whether ‘count’ is equal to 1 then display “The given number is neither Prime not Composite”. Else
display “The given number is Prime”.
Step 7: Stop the program.
Exercise 9:
Step 1: Start the program.
Step 2: Initialize a0, b1 and temp0
Step 3: Read the terms of series to be printed and store it in ‘n’.
Step 4: Print the first two terms of the series, i.e. a & b.
Step 5: Loop the following steps:
temp = a + b
print ‘temp’ value.
a= b
b = temp
Step 6: Repeat step 5, until loop terminates.
Step 7: Stop the program.
Exercise 10:
Step 1: Start the Program
Step 2: The user inputs the number of rows.
Step 3: The outer loop iterates from 1 to n, controlling the rows.
Step 4: The inner loop iterates from 1 to i+1, controlling the number of stars printed in each row.
Step 5: The statement prints stars on the same line.
Step 6: After the inner loop, move to the next line.
Step 7: The outer loop iterates from n down to 1 by decrementing 1, controlling the rows.
Step 8: The inner loop iterates from 1 to i+1, controlling the numbers printed in each row.
Step 9: The statement prints numbers on the same line.
Step 10: After the inner loop, move to the next line.
Step 11: The outer loop iterates from 1 to n, controlling the rows.
Step 12: The inner loop iterates from 0 to i-1, controlling the letters printed in each row.
Step 13: The statement prints the corresponding alphabet letter on the same line. Here, chr(65 + j)
converts the integer 65 + j to the corresponding ASCII character, where 65 is the ASCII code for 'A'.
Step 14: After the inner loop, move to the next line.
Step 15: Stop the Program.
Exercise 11:
Step 1: Start the Program
Step 2: The user inputs the values for x and n.
Step 3: Initialize sum0 and term1.
Step 4: The loop runs from 0 to n (inclusive) to calculate and accumulate each term:
Add the current term to sum.
Update term by multiplying it by x to compute the next term in the series.
Step 5: Repeat step 4, until loop terminates
Step 6: Print the final value of ‘sum’, which represents the sum of the series.
Step 7: Initialize sum0, sign1 and term1.
Step 8: The loop runs from 0 to n (inclusive) to calculate and accumulate each term:
Add the current term to sum, adjusted by the current sign.
Update term by multiplying it by x to compute the next term in the series.
Alternate the sign by multiplying it by -1 for the next iteration.
Step 9: Repeat step 8, until loop terminates
Step 10: Print the final value of ‘sum’, which represents the sum of the alternating series.
Step 11: Initialize sum0 and termx.
Step 12: The loop runs from 0 to n (inclusive) to calculate and accumulate each term:
For each term, compute (x**i)/i and add it to sum.
Update term by multiplying it by x to get x**i for the next term.
Step 13: Repeat step 12, until loop terminates
Step 14: Print the final value of ‘sum’, which represents the sum of the series.
Step 15: Initialize sum0 and sign1.
Step 16: The loop runs from 1 to n (inclusive) to calculate each term of the series:
Compute x**i where i is the current term index.
Compute i! using [Link](i) for the factorial in the denominator.
Add or subtract the term to/from sum based on the current sign.
Alternate the sign for the next iteration by multiplying it by -1.
Step 17: Repeat step 16, until loop terminates
Step 18: Print the final value of ‘sum’, which represents the sum of the series.
Step 19: Stop the program.
Exercise 12:
Step 1: Start the program.
Step 2: Read 2 integer numbers from user and store it in a & b.
Step 3: Find lcm and gcd of the given 2 numbers functions of math module.
Step 4: Print the lcm & gcd of the 2 number.
Step 5: Stop the program.
Exercise 13:
Step 1: Start the program.
Step 2: Read 2 integer numbers to set the range for the randint function of random module as x & y.
Step 3: Assign n1[Link](x,y) and n2[Link](x,y)
Step 4: Find product of the 2 random numbers and store it in ‘product’.
Step 5: Print the Product of 2 random numbers.
Step 6: Read 5 subject marks from user and store it in M, S, E, T and H.
Step 7: Find mean, median and mode using functions of statistics module.
Step 8: Print the mean, median and mode of the 5 given marks.
Step 9: Stop the program.