Posts

Showing posts from March, 2021

Write a program to sum the series:1/1 + 22 /2 + 33 /3 + ……. nn/n

n = int(input("Enter a value of n: ")) s=0.0  for i in range(1,n+1):        a=float(i**i)/i        s=s+a  print("The sum of the series is ", s)  

Factorial Program in python

Image
  Code num = int(input("Enter a Number: "))  if (num == 0):       fact = 1  fact = 1  for i in range(1, num5+1):       fact = fact * i print("Factorial of ", num, " is ", fact) Explaination getting the input using the input function, But the input must be in the input format so for getting the input as integer type use int()  function num = int(input("Enter a Number: ")) Check weather the given number is zero or not if the number is zero then the factorial value will be 1, so we can assume that fact is 1 if (num == 0):   fact = 1 if the entered value is not equal to one then assume one variable fact = 1 and then create a for loop which starts from one to the value we want to find the fact value, And then multiple the previous fact value with the loop value For example:   lets assume the loop value is [1,2,3,4.....n] then it will multiple the fact value with i value and stores the new...