0% found this document useful (0 votes)
26 views

Programs Python

This document contains Python code definitions for several functions: 1) A function to generate and print the first 20 even numbers. 2) A function to check if a number is prime by testing for factors, and print the result. 3) A function to input 10 numbers, find the smallest and largest, and print the results. 4) A function to input 10 numbers, calculate the sum and average, and print the results. 5) Additional functions to calculate the factorial of a number, count the digits in a number, find the occurrence count of a digit in a number, and generate all prime numbers between two given numbers.

Uploaded by

Pragya Bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Programs Python

This document contains Python code definitions for several functions: 1) A function to generate and print the first 20 even numbers. 2) A function to check if a number is prime by testing for factors, and print the result. 3) A function to input 10 numbers, find the smallest and largest, and print the results. 4) A function to input 10 numbers, calculate the sum and average, and print the results. 5) Additional functions to calculate the factorial of a number, count the digits in a number, find the occurrence count of a digit in a number, and generate all prime numbers between two given numbers.

Uploaded by

Pragya Bansal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

FIRST 10 EVEN NO.

S::

def even_number():
print("Generate even nos")
even=[]
for i in range(20):
if(i%2==0):
even.append(i)
print(even)
even_number()

CHECK WHETHER PRIME OR NOT::


def prime_number():
n=int(input("to check prime nos enter number"))
c=int(0)
for i in range(2,(n//2)+1):
if(n%i==0):
c=c+1;
if(c==0):
print("prime")
else:
print("non prime")
prime_number()

INPUT 10 NO.S AND CHECK FOR SMALLEST AND LARGEST::


def smallest_largest():
arr=[]
print("enter 10 no each in new line to check largest and
smallest ")
for _ in range(10):
arr.append(input())
print("largest=",max(arr))
print("smallest=",min(arr))
smallest_largest()

INPUT 10 NO.S AND SHOW FOR SUM AND AVERAGE::


def sum_avg():
arr=[]
print("enter 10 no each in new line to check sum and avg ")
for _ in range(10):
arr.append(int(input()))
print("sum=",sum(arr))
print("avg=",sum(arr)//len(arr))
sum_avg()
FACTORIAL::

def factorial(n):
if(n==0):
return 1
else:
n=n*factorial(n-1)
return n
print(factorial(int(input("enter no for factorial"))))

COUNT THE DIGITS IN A PARTICULAR NUMBER::

def digit_count(n):
c=int(0)
while(n>0):
d=n%10
c=c+1
n=n//10
return c
print(digit_count(int(input("enter no for digit counting"))))

SHOW THE TIMES OF NO. OCCURRED::

def no_times_digit():
n=int(input("enter number for no of times digit occur"))
value=int(input("enter particular value to be checked"))
c=int(0)
while(n>0):
d=n%10
if(d==value):
c=c+1
n=n//10
print( c)
no_times_digit()

TO GENERATE ALL PRIME NO.S BETWEEN X AND Y::


def prime_no_between_x_and_y():
x=int(input("to check prime nos enter number"))
y=int(input("to check prime nos enter number"))
prime=[]
for n in range(x,y):
c=int(0)
for i in range(2,(n//2)+1):
if(n%i==0):
c=c+1;
if(c==0):
prime.append(n)
print(prime)
prime_no_between_x_and_y()

You might also like