Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Introduction To Programming Practical File

Uploaded by

20231113038
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Introduction To Programming Practical File

Uploaded by

20231113038
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

PNR NO.

20231113090
Name :- Jaya Nagar

Aim :-

Section - 1

1. Binary conversion of decimal conversion by loop .


2. Write a program for grading of marks.
3. Write a function which Return Square Cube of a numbers ?
4. Write a program to add , delete and update the element from Tuple.
5. Take a list of 10 elements. Find the average of elements minimum No. & Maximum No.
6. 06 Create a dictionary and find the duplicate entries for values .
7. S = "Dyp1 international 45 university578" calculate the sum and Average of digit present
in string
8. Write the program to count occurrence of all character within string .

Section – 2

1. Write a program to demonstrate element by element multiplication & mathematical


multiplication of matrix for 3*3
2. Plot graph for A graph a = [0:0.5:5], b = [2a^2+3a-5], define the plot by line pattern colour
and thickness .
3. Write program to determine weather given year is leap year or not ?
4. take an array of 10 elements and calculate average and sum of numbers ?
5. Q.05 A=[0:0.5:5] , B=[2a^2+3a-5]& C==[2a^2+4a-3] Plot multiple graph for A&B
Plot A&C Use different pattern for both graph to represent them
PNR NO. 20231113090
Name :- Jaya Nagar

Q. 01 Binary conversion of decimal conversion by loop .

Ans :-

Code For Programme

print("the decimal no. is 10")

decimal = 10

binary = " "

while decimal > 0 :

remainder = decimal % 2

binary = str(remainder)+ binary

decimal = decimal // 2

print("the binary no. is " + binary)


PNR NO. 20231113090
Name :- Jaya Nagar

Q. 02 Write a program for grading of marks.

Ans :-

Code For Programme

print("marks of maths is 80 ")

print("marks of science is 75 ")

print("marks of communication skill is 60 ")

print("marks of Ip is 60 ")

print("marks of fluid is 45 ")

maths = 80

science = 75

communicationskill = 85

Ip =60

fluid = 45

tot = maths+science+communicationskill+Ip+fluid

avg = tot/5

if avg>=91 and avg<=100:

print("Your Grade is A1")

elif avg>=81 and avg<91:

print("Your Grade is A2")

elif avg>=71 and avg<81:

print("Your Grade is B1")

elif avg>=61 and avg<71:

print("Your Grade is B2")

elif avg>=51 and avg<61:

print("Your Grade is C1")

elif avg>=41 and avg<51:

print("Your Grade is C2")

elif avg>=33 and avg<41:

print("Your Grade is D")

elif avg>=21 and avg<33:


PNR NO. 20231113090
Name :- Jaya Nagar

print("Your Grade is E1")

elif avg>=0 and avg<21:

print("Your Grade is E2")

else:

print("Invalid Input!")
PNR NO. 20231113090
Name :- Jaya Nagar

Q. 03 Write a function which Return Square Cube of a numbers ?

Ans :-

Code For Programme

nums = [ 7, 8, 9, 10]

print("Original list of integers:")

print(nums)

print("\nSquare every number of the said list:")

square_nums = list(map(lambda x: x ** 2, nums))

print(square_nums)

print("\nCube every number of the said list:")

cube_nums = list(map(lambda x: x ** 3, nums))

print(cube_nums)
PNR NO. 20231113090
Name :- Jaya Nagar

Q. 04 Write a program to add , delete and update the element from Tuple.

Ans :-

Code For Programme

#programme to add

print("add element in touple")

thistuple = ("apple", "banana", "cherry")

y = list(thistuple)

y.append("orange")

thistuple = tuple(y)

print(thistuple)

#programme to delete

print("delete element in touple")

thistuple = ("apple", "banana", "cherry")

y = list(thistuple)

y.remove("apple")

thistuple = tuple(y)

print(thistuple)

#programme to update

print("update element in touple")

x = ("apple", "banana", "cherry")

y = list(x)

y[1] = "kiwi"

x = tuple(y)

print(x)

Q . 05 Take a list of 10 elements. Find the average of elements minimum No. & Maximum No.

Ans :-

Code For Programme

print("the 10 elements of list is" + " " "15, 9, 55, 41, 35, 20, 62, 49 , 50 , 10")

# Python program to get average of a list

def Average(lst):
PNR NO. 20231113090
Name :- Jaya Nagar

return sum(lst) / len(lst)

lst = [15, 9, 55, 41, 35, 20, 62, 49 , 50 , 10]

average = Average(lst)

print("Average of the list =", round(average, 2))

# Python program to get minimum no. of a list

lst = lst = [15, 9, 55, 41, 35, 20, 62, 49 , 50 , 10]

x=min(lst )

print("the minimum element is",x)

# Python program to get Maximum no. of a list

lst = lst = [15, 9, 55, 41, 35, 20, 62, 49 , 50 , 10]

x=max(lst)

print("the maximum element is",x)


PNR NO. 20231113090
Name :- Jaya Nagar

Q. 06 Create a dictionary and find the duplicate entries for values .

Ans :-

Code For Programme

# initialising dictionary

ini_dict = {'a':1, 'b':2, 'c':3, 'd':2}

print("initial_dictionary", str(ini_dict))

# finding duplicate values

rev_dict = {}

for key, value in ini_dict.items():

rev_dict.setdefault(value, set()).add(key)

result = [key for key, values in rev_dict.items()if len(values) > 1]

# printing result

print("duplicate values", str(result))


PNR NO. 20231113090
Name :- Jaya Nagar

Q. 07 S = "Dyp1 international 45 university578" calculate the sum and Average of digit present in
string

Ans :-

Code For Programme

def sum_digits_string(str1):

sum_digit = 0

for char in str1:

if char.isdigit():

digit = int(char)

sum_digit += digit

return sum_digit

result1 = sum_digits_string("Dyp1 international 45 university578")

print(result1)

average = print(result1/6)
PNR NO. 20231113090
Name :- Jaya Nagar

Q. 08 Write the program to count occurrence of all character within string .

Ans :- Code For Programme

test_str = "abcdabcdabcdabcd"

print("string is abcdabcdabcdabcd")

count = 0

for i in test_str:

if i == 'a':

count = count + 1

print("Count of a in string is : "

+ str(count))

count = 0

for i in test_str:

if i == 'b':

count = count + 1

print("Count of b in string is : "

+ str(count))

count = 0

for i in test_str:

if i == 'c':

count = count + 1

print("Count of c in string is : "

+ str(count))

count = 0

for i in test_str:

if i == 'd':

count = count + 1

print("Count of d in string is : " + str(count))

Q. 01 write a program to demonstrate element by element multiplication & mathematical


multiplication of matrix for 3*3

Ans :-

Code For Programme


PNR NO. 20231113090
Name :- Jaya Nagar

Create two 3-by-3 arrays, A and B, and multiply them element by element.

>> A = [1 0 3; 5 3 8; 2 4 6];

B = [2 3 7; 9 1 5; 8 8 3];

C = A.*B
PNR NO. 20231113090
Name :- Jaya Nagar

Q . 02 Plot graph for A graph a = [0:0.5:5], b = [2a^2+3a-5], define the plot by line pattern color and
thickness .

Ans :-

Code For Programme

a = [0:0.5:5]

a=

0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 4.5000 5.0000

>> b=( 2*a.^2 ) + (3*a) - 5

b=

-5 -3 0 4 9 15 22 30 39 49 60

>> plot(a,b)

>> plot(a,b ,'-r')


PNR NO. 20231113090
Name :- Jaya Nagar

Q.03 Write program to determine weather given year is leap year or not ?

Ans :-

Code For Programme

>> prompt = 'enter the year which you want to check whether it is leap year or not\n';

year = 2024

cond1 = 100;

cond2 = 4;

cond3 = 400;

if(((rem(year,cond2)==0) && ( rem(year,cond1)~=0)) || (rem(year,cond3)==0))

fprintf("entered year %d is a leap year\n",year);

else

fprintf("it is not a leap year:\n");

end

year =

2024

entered year 2024 is a leap year

>>
PNR NO. 20231113090
Name :- Jaya Nagar

Q.04 take an array of 10 elements and calculate average and sum of numbers ?

Ans :-

Code For Programme

x = [1 2 3 4 5 6 7 8 9 10]

theSum = 0;

for k = 1 : length(x);

fprintf('Element %d is: %0.1f \n', k, x(k));

% the sum of numbers

theSum = theSum + x(k);

% Compute the running mean and print out.

fprintf('After element #%d, the sum = %.1f, and the mean = %.3f\n\n',...

k, theSum, theSum/k);

end
PNR NO. 20231113090
Name :- Jaya Nagar

Q.05 A=[0:0.5:5] , B=[2a^2+3a-5]& C==[2a^2+4a-3] Plot multiple graph for A&B

Plot A&C

Use different pattern for both graph to represent them

Ans :-

Code For Programme

>> a = [0;0.5;5]

a=

0.5000

5.0000

>>

b = [2*a.^2+3*a-5]

b=

-5

-3

60

>>

b = [2*a.^2+4*a-3]

b=

-3.0000

-0.5000

67.0000

>> plot(a,b,'--ro')

>> title('first graph')

>> plot(a,c,'-g')

title('second graph')
PNR NO. 20231113090
Name :- Jaya Nagar
PNR NO. 20231113090
Name :- Jaya Nagar

You might also like