Diploma Computer/IT

Programming With Python Practical 13

Programming With Python Practical 13 Question 1 Write a Python program to create two matrices and perform addition, subtraction, multiplication and division operation on matrix. matrix.py import numpy as np a=np.array([]) b=np.array([]) print("Enter elements of first matrix: ") for i in range(0,4): num=int(input("Element:")) a=np.append(a,num) a.shape=(2,2) print("Enter elements of second matrix: ") for i in range(0,4): […]

Programming With Python Practical 13 Read More »

Programming With Python Practical 12

Programming With Python Practical 12 Question 1 Write a Python program to create a user defined module that will ask your college name and will display the name of the college. college.py def getcollege(): cname=input("Enter your college name: ") print("Your college name is: ",cname) collegemain.py import college college.getcollege() Output Question 2 Write a Python program

Programming With Python Practical 12 Read More »

Programming With Python Practical 11

Programming With Python Practical 11 Question 1 Write a Python function that takes a number as a parameter and check the number is prime or not. prime.py def primeno(num): flag=0 for i in range(2,num): if(num%i==0): flag=1 break if(flag==1): print("number is not prime") else: print("number is prime") num=int(input("Enter a number")) primeno(num) Output Question 2 Write a

Programming With Python Practical 11 Read More »

Programming With Python Practical 10

Programming With Python Practical 10 Question 1 Write a Python function that accepts a string and calculate the number of upper case letters and lower case letters. count.py Str=input("Enter a string: ") count1=0 count2=0 for i in Str: if(i.islower()): count1+=1 else: count2+=1 print("The number of lowercase letters is: ",count1) print("The number of uppercase letters is:

Programming With Python Practical 10 Read More »

Programming With Python Practical 9

Programming With Python Practical 9 Question 1 Write a Python script to sort (ascending and descending) a dictionary by value. sort.py my_dict = { 'num1': 6, 'num2': 3, 'num3': 2, 'num4': 4, 'num5': 1, 'num6': 5} sortedVal = sorted(my_dict.values()) keys=[] print("Dictionary in ascending order by values is: ") for val in sortedVal: for k,v in

Programming With Python Practical 9 Read More »

Programming With Python Practical 8

Programming With Python Practical 8 Question 1 Write a Python program to create a set, add member(s) in a set and remove one item from set. createset.py num={10,50,60,40,20,30,80} print("Set is created as :",num) a=int(input("Enter the number to add into set :")) num.add(a) print("After adding set is :",num) b=int(input("Enter the number to remove from set :"))

Programming With Python Practical 8 Read More »

Programming With Python Practical 7

Programming With Python Practical 7 Question 1 Create a tuple and find the minimum and maximum number from it. minmax.py tup=(1,2,3,5,56,9,8,6,4) largest=tup[0] smallest=tup[0] for i in tup: if(i>largest): largest=i for i in tup: if(i<smallest): smallest=i print("Largest number is :",largest) print("Smallest number is :",smallest) Output Question 2 Write a Python program to find the repeated items

Programming With Python Practical 7 Read More »

Programming With Python Practical 6

Programming With Python Practical 6 Question 1 Write a Python program to sum all the items in a list. sum.py list=[10,20,30,50,90,80,6,54] sum=0 for i in list: sum=sum+i print("Sum = ",sum) Output Question 2 Write a Python program to multiplies all the items in a list. multiply.py list=[1,2,3,5,9,8,6,4] result=1 for i in list: result=result*i print("Multiplication =

Programming With Python Practical 6 Read More »

Programming With Python Practical 5

Programming With Python Practical 5 Question 1 Print the following patterns using loop. pattern1.py for i in range(1,5): for j in range(1,i+1): print("*",end="t") print() Output pattern2.py for i in(1,2,3,2,1): for k in range(3-i,0,-1): print(end="t") for j in range(1,2*i): print("*",end="t") print() Output pattern3.py for i in range(1,5): for k in range(1,i): print(end="t") for j in range(8,2*i-1,-1):

Programming With Python Practical 5 Read More »

Programming With Python Practical 4

Programming With Python Practical 4 Question 1 Write a program to check whether a number is even or odd. evenodd.py num=int(input("Enter a number: ")) if(num%2==0): print("Number is even") else: print("Number is odd") Output Question 2 Write a program to find out absolute value of an input number. absolute.py num=int(input("Enter a number: ")) ab=abs(num) print("Absolute value

Programming With Python Practical 4 Read More »