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

Python Code Library (Manual) For Beginner's by DR Kiransing Paradeshi

This Python code library is created by developing python programs for beginners. This is mainly useful for new learners of python. This code library will be helpful to the second year students of any branch of Engineering ,Bsc,Bcom,BCA,students .This manual present the code with outputs Dr Kiransing Paradeshi,PVPIT,Budhgaon
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)
37 views

Python Code Library (Manual) For Beginner's by DR Kiransing Paradeshi

This Python code library is created by developing python programs for beginners. This is mainly useful for new learners of python. This code library will be helpful to the second year students of any branch of Engineering ,Bsc,Bcom,BCA,students .This manual present the code with outputs Dr Kiransing Paradeshi,PVPIT,Budhgaon
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/ 67

PYTHON CODE LIBRARY

For Beginners
Python Practical, S.Y (B.tech)

Dr. Vasantraodada Patil Shetkari Shikshan Mandal’s


Padmabhooshan Vasantraodada Patil Institute of
Technology

Department of Electronics and Computer science Engineering

A Code Library On

“PYTHON PROGRAMS FOR BEGINNERS”

Faculty In charge
Dr K.P.Paradeshi
Python Practical, S.Y (B.tech)

INDEX

Sr. No. Name of Experiment

1. To install python using various installation methods

2. To study the operators using python programming

3. To study control structure and loops using python programming

4. To study string operations and methods using python programming

5. To learn list operations using python programming

6. To learn tuple operations using python programming

7. To learn dictionaries operations using python programming

8. To learn function operations using python programming

9. To learn creating module and packages using python programming

10. To learn creating file data structure using python programming


11. To learn python programming using turtle
Python Practical, S.Y (B.tech)

Practical no 1

Title-To install python using various installation method

Outcomes-

Anaconda Installation for Windows


Step1: Click on the link below to open the downloading page

Step2: Click on the download button and check for the compatibility of your system.

1
Python Practical, S.Y (B.tech)

Step3: Click on Next button

Step4: Read the license agreement and click on “I Agree” button

2
Python Practical, S.Y (B.tech)

Step5: Select installation type

Step6: Choose Installation Location

3
Python Practical, S.Y (B.tech)

Step7: Click the “install” button

Step8: Click on the “Next” button

4
Python Practical, S.Y (B.tech)

Step9: Finishing up the installation

Anaconda Navigator

5
Python Practical, S.Y (B.tech)

Spyder

Jupyter Notebook

6
Python Practical, S.Y (B.tech)

Install Python IDE

Step1: To download and install Python

Step2: Once the download is completed

7
Python Practical, S.Y (B.tech)

Step3: You can see Python installing at this point.

Step4: When it finishes, then now click on “Close”

8
Python Practical, S.Y (B.tech)

Install Pycharm

Step1: To download Pycharm

Step2: Once the download is complete

9
Python Practical, S.Y (B.tech)

Step3: On the next screen

Step4: Choose the start menu folder

10
Python Practical, S.Y (B.tech)

Step5: Wait for the installation to finish

Step6: Once installation finished, then click on “Finish” button

11
Python Practical, S.Y (B.tech)

Step7: After you click on “Finish” button the following screen will appear

12
Python Practical, S.Y (B.tech)

Practical no 2
Title-To study operators using python programming
Programs-
2.1 – A program in python using operators
2.2- A program in python to get area and perimeter of circle, rectangle,
square and triangle

2.3-A program in python to convert the temperature unit from degree to


Fahrenheit

13
Python Practical, S.Y (B.tech)

Practical no 2.1
Program-Basic operators
Num1=int(input("Enter the first number ="))
Num2=int(input("Enter the second number ="))
print("Addition is=",Num1+Num2)
print("Substraction is=",Num1-Num2)
print("Division is=",Num1/Num2)
print("Multiplication is=",Num1*Num2)
print("Modulus is=",Num1%Num2)
print("Floor division is=",Num1//Num2)
print("{a}raise to {b} is=",Num1**Num2)

Output-

14
Python Practical, S.Y (B.tech)

Practical no 2.2
Program-Area and perimeter of circle, triangle, square and rectangle

Output-

15
Python Practical, S.Y (B.tech)

Practical no 2.3
Program-Conversion of temperature

Output-

16
Python Practical, S.Y (B.tech)

Practical no 3
Aim – To study control structure and loop using python programming
Programs -
3.1-To input marks of the student and output the grades
3.2-Finding out the factorial of given number
3.3-Python program to add first 100 numbers
3.4-Python program to add first 50 odd and even numbers
3.5-Python program to get addition of a given number
3.6-Finding out the largest and smallest among three numbers

17
Python Practical, S.Y (B.tech)

Practical no 3.1
Program- To input marks of the student and output the grades

Output-

18
Python Practical, S.Y (B.tech)

Practical no 3.2
Program- Finding out the factorial of given number

Output-

19
Python Practical, S.Y (B.tech)

Practical no 3.3
Program- Python program to add first 100 numbers

Output-

20
Python Practical, S.Y (B.tech)

Practical no 3.4
Program- Python program to add first 50 odd and even numbers

Output-

21
Python Practical, S.Y (B.tech)

Practical no 3.5
Program- Python program to get addition of a given number

Output-

22
Python Practical, S.Y (B.tech)

Practical no 3.6
Program- Finding out the largest and smallest among three numbers

Output-

23
Python Practical, S.Y (B.tech)

Practical no 4
Title- To learn string operations and methods using python programming
Program-
4.1-To study string operation and method using python program
4.2-A program in python to find out number of vowels and other special character
in string

4.3-A program in python to find out distance between character of strings

24
Python Practical, S.Y (B.tech)

Practical no 4.1
Program- To study string operation and method using python programming

25
Python Practical, S.Y (B.tech)

Output-

26
Python Practical, S.Y (B.tech)

Practical no 4.2
Program-A program in python to find out no of vowels and other special
character in string
str=input("Enter the string =")
count_a=0
count_e=0
count_i=0
count_o=0
count_u=0
count_s=0
count_c=0
count_sc=0
count_f=0

for i in range (len(str)):


if(str[i]=='a'):
count_a+=1
elif(str[i]=='e'):
count_e+=1
elif( str[i]=='i'):
count_i+=1
elif( str[i]=='o'):
count_o+=1
elif( str[i]=='u'):
count_u=1
elif(str[i]==" "):
count_s=1
elif(str[i]==','):
count_c=1
elif(str[i]==';'):
count_sc=1
else:
(str[i]=='.')
count_f=1

print("The cout of a is=",count_a)


print("The cout of e is=",count_e)
print("The cout of i is=",count_i)
print("The cout of o is=",count_o)
print("The cout of u is=",count_u)
print("The cout of space is=",count_s)
print("The cout of comma is=",count_c)

27
Python Practical, S.Y (B.tech)

Practical no 4.3
Program- A program in python to find out distance between character of strings
str1=(input(“Enter the first string”))
str2=(input("Enter the second string "))

print(str1)
print(str2)
count=0
l1=len(str1)
l2=len(str2)
if(l1==l2):
for i in range (l1):
dist=ord(str1[i])-ord(str2[i])
count=count+abs(dist)
print(count)
else:
print("Enter the string of equal length")

28
Python Practical, S.Y (B.tech)

Practical no 5
Title-To learn list operations using python programming
Program-
5.1- Enter the list with heterogeneous elements. Carry out all operations such as
concatenation. Indexing, accessing list, reversing list, appending, pop (), insert (),
remove (), etc.

5.2- A python program to generate and store 20 random numbers in a list in the
range 10 to 100. Print the list delete the numbers in between 20 to 50 from a given
list.

5.3- A python program to create a list of random integers using import random
library. Finding out odd, even and prime numbers from the given list.

5.4- A python program to add, subtract, transpose, multiply two matrix using list

29
Python Practical, S.Y (B.tech)

Practical no 5.1
Program- Enter the list with heterogeneous elements. Carry out all operations
such as concatenation. Indexing, accessing list, reversing list, appending, pop (),
insert (), remove (), etc.

30
Python Practical, S.Y (B.tech)

Output-

31
Python Practical, S.Y (B.tech)

Practical no 5.2
Program- A python program to generate and store 20 random numbers in a list in
the range 10 to 100. Print the list delete the numbers in between 20 to 50 from a
given list.

Output-

32
Python Practical, S.Y (B.tech)

Practical 5.3
Program- A python program to create a list of random integers using import
random library. Finding out odd, even and prime numbers from the given list.

Output-

33
Python Practical, S.Y (B.tech)

Practical 5.4
Program- A python program to add, subtract, transpose, multiply two matrix
using list

1) Addition of given matrix

2) Subtraction of given matrix

34
Python Practical, S.Y (B.tech)

3) Multiplication of given matrix

4) Transpose of a matrix

35
Python Practical, S.Y (B.tech)

Practical no 6
Title- To learn tuple operation using python programming
Program-
6.1- A python program to create a tuple, mixed tuple and empty tuple and
performing operations such as :-

- accessing elements of tuple


- performing slicing operation on tuple
- removing empty tuple from nested tuple

6.2- A python program for performing following:-


- create a tuple and add elements in it.
-operations such as concatenation, repeat operations etc.

6.3- Store the data about shares hold by the users as tuples containing the
following information about shares:-
-share name, date of purchase, cost price, no. Of shares, selling price
Write a program to determine:-
- Total cost of portfolio
- Total amount gained / lost
- Percentage profit made or loss included

36
Python Practical, S.Y (B.tech)

Practical no 6.1
Program- A python program to create a tuple, mixed tuple and empty tuple.
Carry out operations such as:-

-access elements of tuple


- performing slicing operation
- remove empty tuple from nested

Output-

37
Python Practical, S.Y (B.tech)

Practical no 6.2
Program- A python program to perform following:-
- create a tuple and add elements in it.
-operations such as concatenation, repeat operations, etc.

38
Python Practical, S.Y (B.tech)

Output-

39
Python Practical, S.Y (B.tech)

Practical no 6.3
Program- Store the data about shares hold by the users as tuples containing the
following information about shares:-
-share name, date of purchase, cost price, no. Of shares, selling price
Write a program to determine:-
- Total cost of portfolio
- Total amount gained / lost
-percentage profit made or loss included

40
Python Practical, S.Y (B.tech)

Output-

41
Python Practical, S.Y (B.tech)

Practical no 7
Title- To learn dictionary operations using python programming
Program-
7.1- A python program to carry out dictionary operations such as creating
dictionary, accessing, values, mixed dictionary, adding key/ value in dictionary,
modifying values, remove element from dictionary, looping/traversing through
dictionary, using value method, using value/key method or items method, copy
method, get method, update method.

7.2- A program in python to create a dictionary of students to get input name, roll
no, course, semester marks obtained in five subjects, total marks, percentage, etc.
Create a record of five students and print the records using dictionary.

7.3- A program in python to create a dictionary containing grocery items and their
prices. Also create another dictionary containing grocery item and their quantity.
By using values from these two dictionaries compute the bill.

42
Python Practical, S.Y (B.tech)

Practical no 7.1
Program- A python program to carry out dictionary operations such as creating
dictionary, accessing, values, mixed dictionary, adding key/ value in dictionary,
modifying values, remove element from dictionary, looping/traversing through
dictionary, using value method, using value/key method or items method, copy
method, get method, update method.

43
Python Practical, S.Y (B.tech)

44
Python Practical, S.Y (B.tech)

Output-

45
Python Practical, S.Y (B.tech)

Practical no 7.2
Program- A program in python to create a dictionary of students to get input
name, roll no, course, semester marks obtained in five subjects, total marks,
percentage, etc. Create a record of five students and print the records using
dictionary.

46
Python Practical, S.Y (B.tech)

Practical no 7.3
Program- A program in python to create a dictionary containing grocery items
and their prices. Also create another dictionary containing grocery item and their
quantity. By using values from these two dictionaries compute the bill.

47
Python Practical, S.Y (B.tech)

Output-

48
Python Practical, S.Y (B.tech)

Practical no 8
Title- To learn function operation using python programming
Program-
8.1- A python program based on types of arguments in functions
-program using required arguments
-program using keyword arguments
-program using default arguments
-program using variable length arguments

8.2-A python program to find factorial of a given number using


-iterative function
-recursive function

8.3-A python program using function to create Fibonacci number series.

8.4- A python program using function to pass number to a function and shift the
list elements to right as many times the given number.

49
Python Practical, S.Y (B.tech)

Practical no 8.1
Program-A python program based on following arguments in functions
-program using required arguments
-program using keyword arguments
-program using default arguments
-program using variable length arguments

1) Required argument

2) Keyword argument

50
Python Practical, S.Y (B.tech)

3) Default argument

4) Variable length argument

51
Python Practical, S.Y (B.tech)

Practical no 8.2
Program-A python program to find factorial of a given number using
-iterative function
-recursive function

Output-

52
Python Practical, S.Y (B.tech)

Practical no 8.3
Program-A python program using function to create Fibonacci number series.

Output-

53
Python Practical, S.Y (B.tech)

Practical no 8.4
Program- A python program using function to pass a number to a function and
shift the list elements to right as many times the given number.

Output-

54
Python Practical, S.Y (B.tech)

Practical no 9
Title- To learn to create module using the python programming
Program-write a module containing function f1 (), f2 (), f3 () use this as module
F1 () =factorial of given no

F2 () =large among three

F3 () =add first 100 number


import mod
print("Enter the correct choice as per your requirement")
print("1 : Factorial of number")
print("2 : Large among three of number")
print("3 : Addition of number upto a particular range")
choice=int(input("Enter your choice="))
if choice==1:
n=int(input("Enter the number of which you want the factorial="))
y=mod.fact(n)
print("The factorial of given number is",y)
elif choice==2:
p=int(input("Enter the first number="))
q=int(input("Enter the second number="))
r=int(input("Enter the third number"))
z=mod.large(p,q,r)
elif choice==3:
t=int(input("Enter the range"))
v=mod.add(t)
print("The addition of natural number upto the given range is",v)
else:
print("Invalid choice")

#from the module file


def fact(a):
if a == 0:
print("Enter the
if x>y and x>z:
print(x,"is the largest number")
elif y>x and y>z:
print(y,"is the largest number")
else:

55
Python Practical, S.Y (B.tech)

print(z,"is the largest number")

def add(s):
sum=0
for i in range(0,s+1):
sum=sum+i
return(sum)

Output-

56
Python Practical, S.Y (B.tech)

Practical no 10
Title- To learn creating file data structure using python programming
Program-
10.1- Create a file in python and write string and list contents into the file.
1) Write the contents into the file
2) Append the contents into the file
3) Read the file using appropriate methods

10.2- Create a text file and write the string “abcdefghijklmnopqrstuvwxyz” into it.
Read the string and print it in reverse order.

57
Python Practical, S.Y (B.tech)

Practical 10.1
Program- Create a file in python and write string and list contents into the file.
1) Write the contents into the file
2) Append the contents into the file
3) Read the file using appropriate methods
string = "Hello, how are you?"

list1 = ["Hello", "how", "are", "you?"]

# Write contents into a file


with open("file1.txt", "w") as file:
file.write(string)

# Read and print the contents of the file


with open("file1.txt", "r") as file:
print(file.read())

# Overwrite the contents of the file with the list items


with open("file1.txt", "w") as file:
file.writelines(list1)

# Read and print the first line of the file


with open("file1.txt", "r") as file:
print(file.readline())

# Read and print all lines of the file as a list


with open("file1.txt", "r") as file:
print(file.readlines())

# Append contents into a file


with open("file1.txt", "a") as file:
file.write("\nI am fine.")

# Read and print the contents of the file


with open("file1.txt", "r") as file:
print(file.read())

# Read and print the first line of the file


with open("file1.txt", "r") as file:
print(file.readline())

# Read and print all lines of the file as a list


with open("file1.txt", "r") as file:
print(file.readlines())

58
Python Practical, S.Y (B.tech)

Output-

59
Python Practical, S.Y (B.tech)

Practical no 10.2
Program- Create a text file and write the string “abcdefghijklmnopqrstuvwxyz”
into it. Read the string and print it in reverse order.

string = "abcdefghijklmnopqrstuvwxyz"

# Write the string into a file


with open("file2.txt", "w") as file:
file.write(string)

# Read the contents of the file, reverse them, and print as a list
with open("file2.txt", "r") as file:
output = list(file.read())
output.reverse()
output = "".join(output)
print(output)

output-

60
Python Practical, S.Y (B.tech)

Practical no 11
Title- To learn python programming using turtle
Program-
11.1- A python program to draw a rectangle using turtle.
11.2- A python program to draw a parallelogram using turtle.

61
Python Practical, S.Y (B.tech)

Practical 11.1
Program- Write a python program to draw a rectangle using turtle.
import turtle

screen = turtle.Screen()

screen.setup(width=750, height=400)

for i in range(2):
pen.forward(200)
pen.right(90)
pen.forward(100)
pen.right(90)

turtle.done()
screen.title("rectangle")

pen = turtle.Turtle()
Output-

62
Python Practical, S.Y (B.tech)

Practical 11.2
Program- Write a python code to draw a parallelogram using turtle.

import turtle

screen = turtle.Screen()

screen.setup(width=750, height=400)

screen.title("rectangle")

pen = turtle.Turtle()

for i in range(2):
pen.forward(200)
pen.right(60)
pen.forward(100)
pen.right(120)

turtle.done()
Output-

63
Python Practical, S.Y (B.tech)

64

You might also like