Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

Lab Manual – Python for Engineers–[CS10202B]

2020-2021 course (FYBTECH)

Bansilal Ramnath Agarwal Charitable Trust’s


Vishwakarma Institute of Information Technology, Pune

Department of Engineering & Applied Science

Students Name: Swarup Suresh Devde


Roll Number: 1431
Gr. Number: 22110558
Class: FY
Division: N
Course Name: Python for Engineers–[CS10202B]

Vishwakarma Institute of Information Technology, Pune Page 1


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Certificate

This is to certify thatMr./Miss-----Swarup Suresh


Picture 7 ...
Devde----------------------------------------------of semester -------1st-------
Branch ------Mechanical--------------Roll No--------1431------------
Gr.No--------22110558-------------------------class-------FY---------------
Division---------N----------has performed the experiments
mentioned above in the institute------VIIT-------------------------
during the year----2021-22-------and has
successfullycompleted all practical’s, in the course
ofPython For Engineersas prescribed.

Date:
Place:

Teacher In-charge Head of Department

Vishwakarma Institute of Information Technology, Pune Page 2


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

TABLE OF CONTENTS
Sr.No. CONTENTS Date Page No.
Install Anaconda and Anaconda Navigators (use of spyder,
1
Jupyter and colab notebook).
Implement Basics of python:
a. Write a program to read (input ()) Celsius temperature and
print (print ()) equivalent Fahrenheit temperate on screen.
Picture 7 ...
b. Write three functions that calculate the remainder of two
integers by using: (a)the basic operators of +, -, * and /
(why is // not required?) (b)the divmod function(c)the %
operator
c. Copy-paste this super-nested Python list-dictionary:
Test=[{‘Arizona’: ‘Phoenix’, ‘California’: ‘Sacramento’,
‘Hawaii’: ‘Honolulu’}, 1000,2000,3000,[‘hat’, ‘t-shirt’,
2 18/01/22
‘jeans’, {‘socks1’: ‘red’, ‘socks2’: ‘blue’}]](a)Return
2000 on your screen. (b)Return the dictionary of the cities
and states on your screen. (This=[{‘Arizona’: ‘Phoenix’,
‘California’: ‘Sacramento’, ‘Hawaii’: ‘Honolulu’}.
(c)Return the list of the clothes on your screen! (This,
[‘hat’, ‘t-shirt’, ‘jeans’, {‘socks1’: ‘red’, ‘socks2’:
‘blue’}]) (d) Return the word ‘Phoenix’ on your screen.
(e) Return the word ‘jeans’ on your screen. (f)Return the
word ‘blue’ on your screen.
Write a Python program to check whether a character is
3 22/02/22
uppercase or lowercase alphabet.
Create a Python script that finds out your age in a maximum
of 10 tries. The script can ask you only one type of question:
4 guessing your age! (e.g. “Are you 67 years old?”) And you 22/02/22
can answer only one of these three options: (a)Less (b)More
(c)Correct
Write a Python program to find factorial of given number
5 (using fact() function). 08/03/22

Write a python program to create two 3X3 random matrixes


and perform following operation: (a) Addition (b) subtraction
6 08/03/22
(c) multiplication and display shape, dimensions, dtype, Rank
and flatten output of every o/p matrix
7 Write a Python program to read a given .txt file and count
total number of ‘the’ in the given file, find total words and
total lines in the file.

Vishwakarma Institute of Information Technology, Pune Page 3


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Picture 7 ...

EXPERIMENT NO: 02

TITLE OF EXPERIMENT: Implement Basics of python:


a. Write a program to read (input ()) Celsius temperature and print (print ()) equivalent
Fahrenheit temperate on screen.
b. Write three functions that calculate the remainder of two integers by using: (a)the basic
operators of +, -, * and / (why is // not required?) (b)the divmod function(c)the % operator
c. Copy-paste this super-nested Python list-dictionary: Test=[{‘Arizona’: ‘Phoenix’,
‘California’: ‘Sacramento’, ‘Hawaii’: ‘Honolulu’}, 1000,2000,3000,[‘hat’, ‘t-shirt’, ‘jeans’,
{‘socks1’: ‘red’, ‘socks2’: ‘blue’}]](a)Return 2000 on your screen. (b)Return the dictionary
of the cities and states on your screen. (This=[{‘Arizona’: ‘Phoenix’, ‘California’:
‘Sacramento’, ‘Hawaii’: ‘Honolulu’}. (c)Return the list of the clothes on your screen!
(This,[‘hat’, ‘t-shirt’, ‘jeans’, {‘socks1’: ‘red’, ‘socks2’: ‘blue’}]) (d) Return the
word ‘Phoenix’ on your screen. (e) Return the word ‘jeans’ on your screen. (f)Return the
word ‘blue’ on your screen.

Vishwakarma Institute of Information Technology, Pune Page 4


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

EXPERIMENT NO: 02

Aim: Implement Basics of python:


a. Write a program to read (input ()) Celsius temperature and print (print ())
equivalent Fahrenheit temperate on screen.
b. Write three functions that calculate the remainder of two integers by using:
(a)the basic operators of +, -, * and / (why is // not required?)
(b)the divmod function
(c)the % operator
c. Copy-paste this super-nested
PicturePython
7 ... list-dictionary: Test=[{‘Arizona’: ‘Phoenix’,
‘California’: ‘Sacramento’, ‘Hawaii’: ‘Honolulu’}, 1000,2000,3000,[‘hat’, ‘t-shirt’, ‘jeans’,
{‘socks1’: ‘red’, ‘socks2’: ‘blue’}]]
(a)Return 2000 on your screen.
(b)Return the dictionary of the cities and states on your screen.
(c)Return the list of the clothes on your screen!
(d) Return the word ‘Phoenix’ on your screen.
(e) Return the word ‘jeans’ on your screen.
(f)Return the word ‘blue’ on your screen.

Program: (Students write program by hand/ type program/ Copy past screen
shot)
a)

tempC=float(input("Enter the temperature in celcius"))

tempF=tempC*1.8+32

print(tempF)

print("temperature in Celcius=",tempC,"C")

print("temperature in Fahrenheit=",tempF,"F")

b)

a=int(input("Enter Number 1:"))

b=int(input("Enter Number 2:"))

print("Remainder=",a-b*(a//b))

print("Remainder=",a%b)

Vishwakarma Institute of Information Technology, Pune Page 5


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

print("Remainder=",divmod(a,b)[1])

c)

Test=[{'Arizona': 'Phoenix', 'California': 'Sacramento', 'Hawaii':


'Honolulu'}, 1000,2000,3000,['hat', 't-shirt', 'jeans', {'socks1': 'red', 'socks2':
'blue'}]]

print(Test[2]) #object 2000 at place 2

print("This=",Test[0])

print("That=",Test[4]) Picture 7 ...

print(Test[0]['Arizona'])

print(Test[4][2])

print(Test[4][3]['socks2'])

Output: (Students write program output by hand/ type program output/Copy


past screen shot)
a)

b)

c)

Vishwakarma Institute of Information Technology, Pune Page 6


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Picture 7 ...

Conclusion:

From this we understand the use of Python variables and basic Operators.
Declaring and using Numeric data types , using string data type and string
operations. Defining list and list slicing, list manipulation using built in
methods.We also learnt use of Tuple data type and Dictionary manipulation.

Vishwakarma Institute of Information Technology, Pune Page 7


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

EXPERIMENT NO : 03

TITLE OF EXPERIMENT: Write a Python program to check whether a character


is uppercase or lowercase alphabet.

EXPERIMENT NO: 03

Aim:Write a Python program to check whether a character is uppercase or lowercase alphabet.


Picture 7 ...

Program: (Students write program by hand/ type program/ Copy past screen
shot)
# Method 1: Without ASCII code
ch = input(print('Enter a character'))
if(ch >= 'A' and ch <= 'Z'): 
       print('Character is uppercase')
elif(ch >= 'a' and ch <='z'):  
       print('Character is lowercase')
elif(ch >= '0' and ch <= '9'):  
       print('Character is decimal')
else:  
       print('Entered value is neither of all') 

# Method 2 :With ASCII


ch = input(print('Enter a character'))
n = ord(ch)
if(n >= 65 and n <= 90): 
     print('Character is uppercase and its ASCII value is',n)
elif(n >= 97 and n <= 122): 
     print('Character is lowercase ASCII value',n)
elif(n >= 48 and n <= 57):
     print('Character is decimal ASCII value',n)
else:  
     print('Entered valued is neither of all')

Output: (Students write program output by hand/ type program output/


Copy past screen shot)

Vishwakarma Institute of Information Technology, Pune Page 8


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

a)

  

Picture 7 ...
b) )

Co
nclusion:

From these we understand how to use Conditional blocks using if , else & elif and
Python Programming using Conditional blocks .

Vishwakarma Institute of Information Technology, Pune Page 9


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Picture 7 ...

EXPERIMENT NO : 04

1. TITLE OF EXPERIMENT: Create a Python script that finds out your age in a
maximum of 10 tries. The script can ask you only one type of question: guessing
your age! (e.g. “Are you 67 years old?”) And you can answer only one of these three
options: (a)Less (b)More (c)Correct

EXPERIMENT NO: 04

Vishwakarma Institute of Information Technology, Pune Page 10


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Aim:Create a Python script that finds out your age in a maximum of 10 tries. The
script can ask you only one type of question: guessing your age! (e.g. “Are you 67
years old?”) And you can answer only one of these three options: (a)Less (b)More
(c)Correct

Program: (Students write program by hand/ type program/ Copy past screen
shot)

Picture 7 ...
min_age = 0
max_age = 100
running = True
for i in range(1,10):
  while running:

    mid=int((min_age + max_age)/2)


    ans=input(f"are you {mid} years old?").lower()

    if ans=='correct':
      print("its correct guess")
      running = False
      break

    elif ans=='more':


      min_age=mid
      print("guess age is more than answer")

    elif ans=='less':


      max_age=mid
      print("guess age is less than answer")

    else:
      print("its wrong choice,please make correction") 

Output: (Students write program output by hand/ type program output/


Copy past screen shot)

Vishwakarma Institute of Information Technology, Pune Page 11


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Picture 7 ...

Conclusion:

From this we understand the using for loop , while loop , if else , elif concept.

Vishwakarma Institute of Information Technology, Pune Page 12


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Picture 7 ...
EXPERIMENT NO : 05

TITLE OF EXPERIMENT: Write a Python program to find factorial of given


number (using fact() function).

EXPERIMENT NO: 05

Aim:Write a Python program to find factorial of given number (using fact() function).

Program: (Students write program by hand/ type program/ Copy past screen
shot)

Vishwakarma Institute of Information Technology, Pune Page 13


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

#1)USING FOR LOOP 

def fact(a):  
       factorial = 1  
       if a < 0:   
           print("Factorial of a negative number does not exist")  
       elif a==0:  
           print("Factorial of 0 is 1")  
       else:   
           for i in range(1,a+1):     Picture 7 ...
                 factorial = factorial*i    
           print("Factorial of given number is", factorial)
k = int(input("Enter your number\n"))
fact(k)  

#2)USING WHILE LOOP

def fact(a):  
      factorial = 1 
      if a < 0:    
            print("Factorial of a negative number does not exist") 
     elif a==0:   
            print("Factorial of 0 is 1") 
     else:     
            i=1    
            while i<=a:       
                   factorial = factorial*i       
                   i=i+1    
            print("Factorial of given number is", factorial)
k = int ( input ( "Enter your number\n" ))
fact(k)
Output: (Students write program output by hand/ type program output/
Copy past screen shot)

1)

Vishwakarma Institute of Information Technology, Pune Page 14


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

2)
Picture 7 ...

Conclusion:

From this we understand how to use the user defined function ; it also
clears the concept of for loop and while loop.

Vishwakarma Institute of Information Technology, Pune Page 15


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Picture 7 ...

EXPERIMENT NO : 06

TITLE OF EXPERIMENT :Write a python program to create two 3X3 random


matrixes and perform following operation: (a) Addition (b) subtraction (c) multiplication
and display shape, dimensions, dtype, Rank and flatten output of every o/p matrix

EXPERIMENT NO: 06

Aim:Write a python program to create two 3X3 random matrixes and perform
following operation: (a) Addition (b) subtraction (c) multiplication and display shape,
dimensions, dtype, Rank and flatten output of every o/p matrix.

Vishwakarma Institute of Information Technology, Pune Page 16


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Program: (Students write program by hand/ type program/ Copy past screen
shot)

import numpy as np
A1 = np.array([[1,2,3],[3,4,5],[6,7,8]]) print("\n1st Matrix=\n",A1)

A2 = np.array([[8,9,10],[11,12,13],[14,15,16]])
print("\n2nd Matrix=\n",A2)
Picture 7 ...
#a)
print("\nAddition of two Matrix=\n",A1+A2)
#b)
print("\n Subtraction of two Matrix=\n",A1-A2)
#c)
print("\n Multiplication of two Matrix=\n",A1*A2)

print("Shape of first matrix=",A1.shape) print("Dimension of first


matrix=",A1.ndim)
print("Type of first matrix=",A1.dtype) print("Converting 2D to 1D of first
matrix=",A1.flatten())

Output: (Students write program output by hand/ type program output/


Copy past screenshot)

Vishwakarma Institute of Information Technology, Pune Page 17


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Picture 7 ...

Conclusion:

We understand the use of numpy and performed arithmetic operations like


addition, subtraction and multiplication with matrices.

Vishwakarma Institute of Information Technology, Pune Page 18


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

Picture 7 ...

EXPERIMENT NO : 07

TITLE OF EXPERIMENT : Write a Python program to read a given .txt file and
count total number of ‘the’ in the given file, find total words and total lines in the file

Vishwakarma Institute of Information Technology, Pune Page 19


Lab Manual – Python for Engineers–[CS10202B]
2020-2021 course (FYBTECH)

EXPERIMENT NO: 07

Aim:Write a Python program to read a given .txt file and count total number of ‘the’ in
the given file, find total words and total lines in the file.

Picture 7 ...
Program: (Students write program by hand/ type program/ Copy past screen
shot)

Output: (Students write program output by hand/ type program output/


Copy past screen shot)

Conclusion:

Vishwakarma Institute of Information Technology, Pune Page 20

You might also like