How to find the factorial of a number in python without using predefined functions| Write a python program to find the number of occurence of even and odd numbers|Basic computer science python programs

 

Introduction

In this blog you will Get three programs.
In First Code you will learn to find the factorial of a number in python without using predefined functions. This is a basic approach for finding factorial of a number.
In Second Code you will learn to find the number of occurence of even and odd numbers.

Source code (first)-
num=int(input("Enter a number"))
fact=1
if num<0:
print("factorial doesnt exist")
elif num==0:
print("factorial=1")
else:
for i in range(1,num+1):
fact=fact*i
print("factorial of the given number is:",fact)

#CODE ENDED


Output-


Source code (Second)-
list1=eval(input("Enter your number :"))
even=0
odd=0
for num in list1:
if num%2==0:
even=even+1
else:
odd=odd+1
print("Even number in the list are:",even)
print("odd numbers in the list are:",odd)
#CODE ENDED




Output-



"Hope it helped"
Have anything in mind? Let me 
know in the comment section👇

Next Post Previous Post
No Comment
Add Comment
comment url