0% found this document useful (0 votes)
3 views4 pages

Untitled Document

Uploaded by

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

Untitled Document

Uploaded by

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

1.

To print the HCF of two numbers:

def compute_hcf(x, y):

if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if((x % i == 0) and (y % i == 0)):
hcf = i
return hcf

num1 =
num2 =

print("The H.C.F. is", compute_hcf(num1, num2))

2. To check the number is prime or co-prime:

num = int(input("Enter a number: "))

flag = False

if num == 0 or num == 1:
print(num, "is not a prime number")
elif num > 1:

for i in range(2, num):


if (num % i) == 0:
flag = True

if flag:
print(num, "is not a prime number")
else:
print(num, "is a prime number")

3. To print the factorial of a number:

num = int(input("Enter a number: "))

factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative
numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)

5. Enter 10 numbers and print the greatest number:

a = [10, 24, 76, 23, 12]


largest = max(a)
print(largest)

6. To print the content of a list containing 10 numbers:

a= list[1,2,3,4,5,6,7,8,9,0]
print(a)

7. To print the content of a tuple content of a tuple containing 10


integers:

tuplel=(1,2,3,4,5,6,7,8,9,0)
print(tuplel)

8. Enter 10 number and print in ascending order:

a = [5, 2, 9, 1, 5, 6]
a.sort()
print(a)

9. Program to print a line graph:

import matplotlib.pyplot as plt


import numpy as np

x = np.array([1, 2, 3, 4])
y = x*2

plt.plot(x, y)
plt.show()

10. Program to plot a bar graph:

import numpy as np
import matplotlib.pyplot as plt

data = {'C':20, 'C++':15, 'Java':30, 'Python':35}


courses = list(data.keys())
values = list(data.values())

fig = plt.figure(figsize = (10, 5))


plt.bar(courses, values, color ='maroon', width = 0.4)

plt.xlabel("Courses offered")
plt.ylabel("No. of students enrolled")
plt.title("Students enrolled in different courses")
plt.show()

11. Program to show a scatter plot:

import matplotlib.pyplot as plt

x =[5, 7, 8, 7, 2, 17, 2, 9,
4, 11, 12, 9, 6]

y =[99, 86, 87, 88, 100, 86,


103, 87, 94, 78, 77, 85, 86]

plt.scatter(x, y, c ="blue")

plt.show()

12. Draw a circle:

import turtle

t = turtle.Turtle()
r = 50
t.circle(r)

13. Display a image:

import sys # to access the system


import cv2
img = cv2.imread("sheep.png", cv2.IMREAD_ANYCOLOR)

while True:
cv2.imshow("Sheep", img)
cv2.waitKey(0)
sys.exit() # to exit from all the processes

cv2.destroyAllWindows() # destroy all windows


14. Display a rectangle:

import turtle
t = turtle.Turtle()

l = int(input("Enter the length of the Rectangle:"))


w = int(input("Enter the width of the Rectangle: "))

t.forward(l)
t.left(90)

t.forward(w)
t.left(90)

t.forward(l)
t.left(90)

t.forward(w)
t.left(90)

15. Plot a histogram:

import matplotlib.pyplot as plt


import numpy as np

data = np.random.randn(1000)

plt.hist(data, bins=30, color='skyblue',


edgecolor='black')

plt.xlabel('Values')
plt.ylabel('Frequency')
plt.title('Basic Histogram')

plt.show()

You might also like