Python Programming |S.Y. ECS - B 1 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
2.
Python Programming |S.Y. ECS - B 2 Electronics and Computer Science, PVPIT Budhgaon Practical No. 1 Title – To install python using various installation method 1. a. 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.
3.
Python Programming |S.Y. ECS - B 3 Electronics and Computer Science, PVPIT Budhgaon Step3: Click on Next button Step4: Read the license agreement and click on “I Agree” button
4.
Python Programming |S.Y. ECS - B 4 Electronics and Computer Science, PVPIT Budhgaon Step5: Select installation type Step6: Choose Installation Location
5.
Python Programming |S.Y. ECS - B 5 Electronics and Computer Science, PVPIT Budhgaon Python Practical, S.Y (B.tech) Step7: Click the “install” button Step8: Click on the “Next” button
6.
Python Programming |S.Y. ECS - B 6 Electronics and Computer Science, PVPIT Budhgaon Step9: Finishing up the installation Anaconda Navigator
7.
Python Programming |S.Y. ECS - B 7 Electronics and Computer Science, PVPIT Budhgaon Spyder Jupyter Notebook
8.
Python Programming |S.Y. ECS - B 8 Electronics and Computer Science, PVPIT Budhgaon 1. b. Install Python IDE Step1: To download and install Python Step2: Once the download is completed
9.
Python Programming |S.Y. ECS - B 9 Electronics and Computer Science, PVPIT Budhgaon Step3: You can see Python installing at this point. Step4: When it finishes, then now click on “Close”
10.
Python Programming |S.Y. ECS - B 10 Electronics and Computer Science, PVPIT Budhgaon Python IDE Interface Google Colab Interface
11.
Python Programming |S.Y. ECS - B 11 Electronics and Computer Science, PVPIT Budhgaon 1. c. Install Pycharm Step1: To download Pycharm Step2: Once the download is complete
12.
Python Programming |S.Y. ECS - B 12 Electronics and Computer Science, PVPIT Budhgaon Step3: On the next screen Step4: Choose the start menu folder
13.
Python Programming |S.Y. ECS - B 13 Electronics and Computer Science, PVPIT Budhgaon Step5: Wait for the installation to finish Step6: Once installation finished, then click on “Finish” button
14.
Python Programming |S.Y. ECS - B 14 Electronics and Computer Science, PVPIT Budhgaon Step7: After you click on “Finish” button the following screen will appear PyCharm IDE
15.
Python Programming |S.Y. ECS - B 15 Electronics and Computer Science, PVPIT Budhgaon References: Official website: https://www.anaconda.com/ Anaconda Distribution: https://www.anaconda.com/products/individual Official website: https://www.jetbrains.com/pycharm/ Official website (Python.org): https://www.python.org/ Python IDLE Documentation: https://docs.python.org/3/library/idle.html VS Code: https://code.visualstudio.com/downloadd Google Colab: https://colab.research.google.com/#scrollTo=Wf5KrEb6vrkR
16.
Python Programming |S.Y. ECS - B 16 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
17.
Python Programming |S.Y. ECS - B 17 Electronics and Computer Science, PVPIT Budhgaon Practical No. 2 Title – To study the operators using python programming a. Integer arithmetic operations b. Float arithmetic operations c. Calculate the area and circumference of Circle and Rectangle d. Convert the temperature from 0 C to 0 F and 0 F to 0 C 2. a. Integer arithmetic operations Python Code: num_1 = int(input("Enter the first number= ")) num_2 = int(input("Enter the second number= ")) res_add = num_1 + num_2 print("The result of addition is =", res_add) res_sub = num_1 - num_2 print("The result of subtraction is =", res_sub) res_mul = num_1 * num_2 print("The result of multiplication is =", res_mul) res_div = num_1 / num_2 print("The result of division is =", res_div) res_floor_div = num_1 // num_2 print("The result of floor division is =", res_floor_div) res_modulus = num_1 % num_2 print("The result of modulus operation is =", res_modulus) res_exponentiation = num_1 ** num_2 print("The result of exponentiation is =", res_exponentiation)
18.
Python Programming |S.Y. ECS - B 18 Electronics and Computer Science, PVPIT Budhgaon res_abs = abs(-10) print("The result of absolute operation is =", res_abs) res_round = round(res_div, 2) print("The result of rounding operation is =", res_round) Result:
19.
Python Programming |S.Y. ECS - B 19 Electronics and Computer Science, PVPIT Budhgaon 2 b. Float arithmetic operations Python Code: num_1 = float(input("Enter the first number= ")) num_2 = float(input("Enter the second number= ")) res_add = num_1 + num_2 print("The result of addition is =", res_add) res_sub = num_1 - num_2 print("The result of subtraction is =", res_sub) res_mul = num_1 * num_2 print("The result of multiplication is =", res_mul) res_div = num_1 / num_2 print("The result of division is =", res_div) res_floor_div = num_1 // num_2 print("The result of floor division is =", res_floor_div) res_modulus = num_1 % num_2 print("The result of modulus operation is =", res_modulus) res_exponentiation = num_1 ** num_2 print("The result of exponentiation is =", res_exponentiation) res_abs = abs(res_div) print("The result of absolute operation is =", res_abs) res_round = round(res_div, 2) print("The result of rounding operation is =", res_round)
20.
Python Programming |S.Y. ECS - B 20 Electronics and Computer Science, PVPIT Budhgaon Result:
21.
Python Programming |S.Y. ECS - B 21 Electronics and Computer Science, PVPIT Budhgaon 2 c. Calculate the area and circumference of Circle and Rectangle Python Code: Choice = int(input("Enter 1 for Circle and 2 for Rectangle ")) if (Choice == 1): r = float(input("Enter the value of Radius ")) pi = 3.14 Area = pi * r * r Circum = 2 * pi * r print("Area of Circle = ", Area) print("Circumference of Circle = ", Circum) elif (Choice == 2): side_1 =float(input("Enter the value first side of Rectangle ")) side_2 =float(input("Enter the value second side of Rectangle ")) Area = side_1 * side_2 Circum = 2 * (side_1 + side_1) print("Area of Rectangle = ", Area) print("Circumference of Rectangle = ", Circum) Result:
22.
Python Programming |S.Y. ECS - B 22 Electronics and Computer Science, PVPIT Budhgaon 2 d . Convert the temperature from 0 C to 0 F and 0 F to 0 C Python Code: choice = int(input("Enter 1 for C to F conversion and 2 for F to C conversion ")) if(choice == 1): Celsius = float(input("Enter the vaue temerature in Celsius ")) Far = Celsius*(9/5)+32 print("The value of temperature in Fahrenheit = ", Far) elif(choice == 2): Far = float(input("Enter the vaue temerature in Fahrenheit ")) cel = (Far - 32)*(5/9) print("The value of temperature in Celsius = ", cel) Result:
23.
Python Programming |S.Y. ECS - B 23 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
24.
Python Programming |S.Y. ECS - B 24 Electronics and Computer Science, PVPIT Budhgaon Practical No. 3 Title – To study control structure and loops using python programming a. To accept the marks of the student and convert them to grades b. Finding out the factorial of given number c. Python program to add first 100 numbers d. Python program to get addition of digits of a given number e. Finding out the largest and smallest among three numbers 3. a. To accept the marks of the student and convert them to grades Python Code: eng = int(input("Enter the marks of English ")) phy = int(input("Enter the marks of Physics ")) chem = int(input("Enter the marks of Chemistry ")) maths = int(input("Enter the marks of Mathemetics ")) bio = int(input("Enter the marks of Biology ")) total = eng + phy + chem + maths + bio print("Total Marks = ", total) percen = (total/500) * 100 print("The percentage = ", percen) if (percen > 90): print("Congratulations... Your Grade is A+") elif (percen < 90 and percen >= 80): print("Congratulations... Your Grade is A") elif (percen < 80 and percen >= 70): print("Your Grade is B+") elif (percen < 70 and percen >= 60): print("Your Grade is B") elif (percen < 60 and percen >= 50): print("Your Grade is C+") elif (percen < 50 and percen >= 40): print("Your Grade is C") else: print("Your Grade is FAIL")
25.
Python Programming |S.Y. ECS - B 25 Electronics and Computer Science, PVPIT Budhgaon Result:
26.
Python Programming |S.Y. ECS - B 26 Electronics and Computer Science, PVPIT Budhgaon 3. b. Finding out the factorial of given number Python Code: num = int(input("Enter the number = ")) fact = 1 for i in range (1, num+1): fact = fact * i print("Factorial of given number is ", fact) Result:
27.
Python Programming |S.Y. ECS - B 27 Electronics and Computer Science, PVPIT Budhgaon 3. c. Python program to add first 100 numbers Python Code: sum = 0 for i in range (1, 101): sum = sum + i print("Sum of first 100 number is ", sum) Result:
28.
Python Programming |S.Y. ECS - B 28 Electronics and Computer Science, PVPIT Budhgaon 3. d. Python program to get addition of digits of a given number Python Code: num = int(input("Enter the number = ")) sum = 0 while (num!= 0): temp = num % 10 sum = sum + int(temp) num = num/10 print("Sum digits of given number is ", sum) Result:
29.
Python Programming |S.Y. ECS - B 29 Electronics and Computer Science, PVPIT Budhgaon 3. e. Finding out the largest and smallest among three numbers Python Code: num1 = int(input("Enter the first number = ")) num2 = int(input("Enter the second number = ")) num3 = int(input("Enter the third number = ")) if (num1>num2 and num1>num3): print(num1, "is the greater number") elif (num2>num1 and num2>num3): print(num2, "is the greater number") else: print(num3, "is the greater number") if (num1<num2 and num1<num3): print(num1, "is the smaller number") elif (num2<num1 and num2<num3): print(num2, "is the smaller number") else: print(num3, "is the smaller number") Result:
30.
Python Programming |S.Y. ECS - B 30 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
31.
Python Programming |S.Y. ECS - B 31 Electronics and Computer Science, PVPIT Budhgaon Practical No. 4 Title – To study string operations and methods using python programming a. String operations: Concatenation, Appending, Indexing and Slicing b. A program in python to find out number of vowels and other special character in string c. A program in python to find out distance between character of strings 4. a. String operations: Concatenation, Appending, Indexing and Slicing Python Code: str_1 = input("Enter first String = ") str_2 = input("Enter second String = ") # String Concatenation str_conca = str_1 + ' ' + str_2 print(str_conca) # String appending str_1 += str_2 print(str_1) print(f"Index of I is {str_1.index('I')}") # Slicing = 1 to 3 letters print(str_1[1:4]) # Accesses first character: +ve indexing print(str_1[0])
32.
Python Programming |S.Y. ECS - B 32 Electronics and Computer Science, PVPIT Budhgaon # Accesses last character: -ve indexing print(str_2[-1]) Result:
33.
Python Programming |S.Y. ECS - B 33 Electronics and Computer Science, PVPIT Budhgaon 4. b. A program in python to find out number of vowels in string Python Code: str = input("Enter the String = ") count_a=0 count_e=0 count_i=0 count_o=0 count_u=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 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)
34.
Python Programming |S.Y. ECS - B 34 Electronics and Computer Science, PVPIT Budhgaon Result:
35.
Python Programming |S.Y. ECS - B 35 Electronics and Computer Science, PVPIT Budhgaon 4. c. A program in python to find out distance between character of strings Python Code: str_1 = input("Enter the first string ") str_2 = input("Enter the second string ") print(str_1) print(str_2) count=0 l1=len(str_1) l2=len(str_2) if(l1==l2): for i in range (l1): dist = ord(str_1[i]) - ord(str_2[i]) count = count + abs(dist) print(count) else: print("Enter the string of equal length") Result:
36.
Python Programming |S.Y. ECS - B 36 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
37.
Python Programming |S.Y. ECS - B 37 Electronics and Computer Science, PVPIT Budhgaon Practical No. 5 Title – To learn list operations using python programming a. Enter the list with heterogeneous elements. Carry out all operations such as concatenation. Indexing, accessing list, reversing list, appending, pop (), insert (), remove (), etc. b. A python program to generate and store 20 random numbers in a list in the range 11 to 99. Print the list delete the numbers in between 30 to 60 from a given list. c. A python program to create a list of 10 random integers using import random library (within 1 to 20). Finding out odd, even numbers from the given list. 5. a. Enter the list with heterogeneous elements. Carry out all operations such as concatenation. Indexing, accessing list, reversing list, appending, pop (), insert (), remove (), etc. Python Code: list_1 = ['rohit', 'virat', 45, 18] list_2 = ['apple', 'banana', 11, 5] print("List 1 is =", list_1) print("List 2 is =", list_2) # Concatenation list_3 = list_1 + list_2 print("List concatenation =", list_3) # Indexing print("Index of virat is = ", list_3.index('virat'))
38.
Python Programming |S.Y. ECS - B 38 Electronics and Computer Science, PVPIT Budhgaon # Accessing element print("The element at index 4 in list 3 is = ", list_3[4]) # Reversing List list_3.reverse() print("list 3 after reversing is = ", list_3) # Appending list_3.append("PVPIT") print("List 3 with appending PVPIT is = ", list_3) # pop() print("POP function on index 4 in list 3 is = ", list_3.pop(4)) # insert() list_3.insert(1, "ECS") print("List 3 with inserting ECS at 1 index is = ", list_3) # remove() list_3.remove(5) print("List 3 after removing numbers is = ", list_3) Result:
39.
Python Programming |S.Y. ECS - B 39 Electronics and Computer Science, PVPIT Budhgaon 5. b. A python program to generate and store 20 random numbers in a list in the range 11 to 99. Print the list delete the numbers in between 30 to 60 from a given list. Python Code: import random a = [] b = [] print(a, b) for i in range (20): k = random.randint(11, 99) a.append(k) print (a) for j in a: if (j >= 30 and j <= 60): del j else: b.append(j) print (b) Result:
40.
Python Programming |S.Y. ECS - B 40 Electronics and Computer Science, PVPIT Budhgaon 5. c. A python program to create a list of 10 random integers using import random li brary (within 1 to 20). Finding out odd, even numbers from the given list. Python Code: import random a = [] even_no = [] odd_no = [] for i in range (10): k = random.randint (1, 20) a.append(k) print("Random numbers generated are as followsn", a) for i in a: if (i % 2 == 0): even_no.append(i) else: odd_no.append(i) print("The Even numbers are as followsn", even_no) print("The Odd numbers are as followsn", odd_no) Result:
41.
Python Programming |S.Y. ECS - B 41 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
42.
Python Programming |S.Y. ECS - B 42 Electronics and Computer Science, PVPIT Budhgaon Practical No. 6 Title – To learn tuple operations using python programming a. 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 b. A python program to perform following - create a tuple and add elements in it. - operations such as concatenation, repeat operations, etc 6. a. 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 Python Code: tuple_1= (1,2,3,4,5,6,7,8,9) mixed_tuple = (5, "ECS", 3.142, (), 'h', (5,6,7)) empty_tuple = () print(tuple_1) print(mixed_tuple) print(empty_tuple) #Accessing element in tuple throgh indexing print ("Accessing 6th element from tuple_1 = ", tuple_1[5])
43.
Python Programming |S.Y. ECS - B 43 Electronics and Computer Science, PVPIT Budhgaon #Tuple Slicing print ("After Slicing tuple_1, the result is = ", tuple_1[2:5]) # Removing Empty tuple print("Mixed_tuple =", mixed_tuple) for i in mixed_tuple: if type(i) == tuple: if len(i) == 0: ls = list(mixed_tuple) ls.remove(i) mixed_tuple = tuple(ls) print("Mixed Tuple after removing empty tuple is =n", mixed_tuple) Result:
44.
Python Programming |S.Y. ECS - B 44 Electronics and Computer Science, PVPIT Budhgaon 6. b. A python program to perform following - create a tuple and add elements in it. - operations such as concatenation, repeat operations, etc Python Code: # Creating Tuple tpl = () ls = list(tpl) no_of_elements = int(input("Enter the number of elements you want in tuple ")) for i in range (no_of_elements): element = int(input("Enter the element = ")) ls.append(element) tpl_1 = tuple(ls) print("tuple 1 = ", tpl_1) #Concatenation of tuple tpl_2 = (1, 3, 5, 3, 8) print("tuple 2 = ", tpl_2) ls_2 = list(tpl_2) ls_3 = ls + ls_2 tpl_3 = tuple(ls_3) print("Result of tuple concateation is = ", tpl_3)
45.
Python Programming |S.Y. ECS - B 45 Electronics and Computer Science, PVPIT Budhgaon # Functions print("Maximum element in tuple is = ", max(tpl_3)) print("Minimum element in tuple is = ", min(tpl_3)) print("Sum of elements in tuple is = ", sum(tpl_3)) print("Length of tuple is = ", len(tpl_3)) Result:
46.
Python Programming |S.Y. ECS - B 46 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
47.
Python Programming |S.Y. ECS - B 47 Electronics and Computer Science, PVPIT Budhgaon Practical No. 7 Title – To learn dictionaries operations using python programming a. 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. b. A program in python to create a dictionary of students to get input name, roll no, course, semester marks obtained in f subjects, total marks, percentage, etc. Create a record of four students and print the records using dictionary. 7. a. 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. Python Code: dict_1 = {"Roll_No":31, "Name":"A B Shinde", "Age":45, "City":"Sangli"} # Output using print print("Output using print method") print(dict_1)
48.
Python Programming |S.Y. ECS - B 48 Electronics and Computer Science, PVPIT Budhgaon # Output using values method print("Output using value method") for i in dict_1.values(): print(i) # Output using key-value method print("Output using key-value method") for i,j in dict_1.items(): print(f"{i},{j}") # Adding elements in the Dictionary dict_1["Class"] = "Teacher" print(dict_1) # Modifying the dictionary element dict_1["City"] = "Pandharpur" print(dict_1) # Deleting elements in dictionary dict_1.pop("Age") print(dict_1) # Transversing through dictionary for i in dict_1.values(): print(i)
49.
Python Programming |S.Y. ECS - B 49 Electronics and Computer Science, PVPIT Budhgaon Result:
50.
Python Programming |S.Y. ECS - B 50 Electronics and Computer Science, PVPIT Budhgaon 7. b. A program in python to create a dictionary of students to get input name, roll no, course, semester marks obtained in f subjects, total marks, percentage, etc. Create a record of four students and print the records using dictionary. Python Code: students = {} # Accept the common data of 10 students: loop for i in range (4): print("n") # Accept the data of each student roll_no = input("Enter the Roll Number : ") name = input("Enter the Name of Student : ") course = input("Enter the Course in which Student is enrolled : ") sem = input("Enter the Semester : ") Python = input("Enter the Marks of Python : ") DMS = input("Enter the Marks of DMS : ") BHR = input("Enter the Marks of BHR : ") PTRP = input("Enter the Marks of PTRP : ") Seminar = input("Enter the Marks of Seminar : ") # Creating the nested dictionary for each Student students[roll_no] = {} students[roll_no]["name"] = name students[roll_no]["course"] = course students[roll_no]["sem"] = sem
Python Programming |S.Y. ECS - B 52 Electronics and Computer Science, PVPIT Budhgaon
53.
Python Programming |S.Y. ECS - B 53 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
54.
Python Programming |S.Y. ECS - B 54 Electronics and Computer Science, PVPIT Budhgaon Practical No. 8 Title – To learn function operations using python programming a. 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 b. A python program to find factorial of a given number using - iterative function - recursive function c. A python program using function to create Fibonacci number series. 8. a. 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 Python Code: #Required Arguments def sum(a,b,c): return(a+b+c) total = sum(2,4,6) print("The Sum of three numbers is = ", total) #Keyword Arguments def sum(a,b,c): return(a+b+c) total = sum(a=2,b=4,c=5)
55.
Python Programming |S.Y. ECS - B 55 Electronics and Computer Science, PVPIT Budhgaon print("The Sum of three numbers is = ", total) #Default Arguments def sum(a,b,c=9): return(a+b+c) total = sum(2,4) print("The Sum of three numbers is = ", total) #Variable Length Arguments def student(course,sem,*paper): print("Course of Student is ", course) print("Semester of Student is ", sem) for i in paper: print("papers are ", i) student ("BTech", 2, "Python", "DM", "DBMS", "PTRP") Result:
56.
Python Programming |S.Y. ECS - B 56 Electronics and Computer Science, PVPIT Budhgaon 8. b. A python program to find factorial of a given number using - iterative function - recursive function Python Code: # Ietrative Function num=int(input("Enter the number = ")) def fact(a): fact = 1 for i in range (1, a+1): fact = fact*i print("Factorial of given number using iterative function is = ", fact) fact(num) # Recursive Function def facto(num): #Factorial of 0 or negative number is 1 if (num < 1): return 1 else: return num * facto(num - 1) print("The factorial of {num} using recursive functionis = ", facto(num))
57.
Python Programming |S.Y. ECS - B 57 Electronics and Computer Science, PVPIT Budhgaon Result: 8. c. A python program using function to create Fibonacci number series. Python Code: # Python code to create finbbonanci number series def f_series(n): if (n <= 1): return n else: return f_series(n-1) + f_series(n-2) n = int(input("Enter the number = ")) series = [f_series(i) for i in range (n+1)] print("Fibbonanci Series till", n , "number is n") for i in series: print (i, end = ", ") print("n") Result:
58.
Python Programming |S.Y. ECS - B 58 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
59.
Python Programming |S.Y. ECS - B 59 Electronics and Computer Science, PVPIT Budhgaon Practical No. 9 Title – To learn creating module using python programming a. Write a python module containing function f1 (), f2 (), f3 () use this as module for f1 () = Factorial of given no. f2 () = Largest among three f3 () = Add first 100 number b. Write a python module “calculator” to create all integer operations like Add, Subtract, Multiply, Divide, Floor Division, Modulus, Exponentiation etc. 9. a. A. Write a python module containing function f1 (), f2 (), f3 () use this as module for f1 () = Factorial of given no. f2 () = Largest among three f3 () = Add first 100 number Python Code: Module: mod_abs # Factorial function def fact(a): fact = 1 for i in range (1, a+1): fact = fact*i print("Factorial of given number is = ", fact)
60.
Python Programming |S.Y. ECS - B 60 Electronics and Computer Science, PVPIT Budhgaon def largest(x,y,z): if (x>y and x>z): print(x, "is the greater number") elif (y>x and y>z): print(y, "is the greater number") else: print(z, "is the greater number") def sum(s): sum = 0 for i in range (0,s+1): sum = sum + i print("The sum of digits from 0 to given numbers is = ", sum) import mod_abs print("Press 1 to calculate Factorial of given number" ) print("Press 2 to calculate Largest number" ) print("Press 3 to calculate the sum from 0 to given number" ) Choice = int(input("Enter your Choice ")) if (Choice == 1): n = int(input("Enter the number to calculate the Factorial = ")) fac = mod_abs.fact(n) 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_abs.largest(p,q,r)
61.
Python Programming |S.Y. ECS - B 61 Electronics and Computer Science, PVPIT Budhgaon elif (Choice == 3): t = int(input("Enter the number ")) d = mod_abs.sum(t) else: print("Enter the correct Choice") Result:
62.
Python Programming |S.Y. ECS - B 62 Electronics and Computer Science, PVPIT Budhgaon 9. b. Write a python module “calculator” to create all integer operations like Add, Subtract, Multiply, Divide, Floor Division, Modulus, Exponentiation etc. Python Code: Module: calculator # Calculator Module def add(x,y): return (x+y) def sub(x,y): return (x-y) def mul(x,y): return (x*y) def div(x,y): return (x/y) def floor_div(x,y): return(x//y) def modu(x,y): return(x%y) def expo(x,y): return(x**y)
63.
Python Programming |S.Y. ECS - B 63 Electronics and Computer Science, PVPIT Budhgaon import calculator num_1 = int(input("Enter the first number= ")) num_2 = int(input("Enter the second number= ")) r_add = calculator.add(num_1, num_2) print("The result of addition is =", r_add) r_sub = calculator.sub(num_1, num_2) print("The result of subtraction is =", r_sub) r_mul = calculator.mul(num_1, num_2) print("The result of multiplication is =", r_mul) r_div = calculator.div(num_1, num_2) print("The result of devision is =", r_div) r_f_div = calculator.floor_div(num_1, num_2) print("The result of floor division is =", r_f_div) r_modu = calculator.modu(num_1, num_2) print("The result of modulus is =", r_modu) r_expo = calculator.expo(num_1, num_2) print("The result of exponentiation is =", r_expo)
64.
Python Programming |S.Y. ECS - B 64 Electronics and Computer Science, PVPIT Budhgaon Result:
65.
Python Programming |S.Y. ECS - B 65 Electronics and Computer Science, PVPIT Budhgaon Dr. V. P. Shetkari Shikshan Mandal’s Padmabhooshan Vasantraodada Patil Institute of Technology, Budhgaon-416304 Department of Electronics and Computer Science Engineering Python Programming Experiment No. : Name of Experiment: Roll Number : Date Performed : Date Checked : Signature (Batch In-charge)
66.
Python Programming |S.Y. ECS - B 66 Electronics and Computer Science, PVPIT Budhgaon Practical No. 10 Title – To learn creating file data structure using python programming a. 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 b. Create a text file and write the string “abcdefghijklmnopqrstuvwxyz” into it. Read the string and print it in reverse order. 10. a. 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 Python Code: # Writing contents to the file str = "Hello, How are you?" # Write contents to the file with open("file1.txt", "w") as file: file.write(str) # Read and print the contents of the file with open("file1.txt", "r") as file: print(file.read())
67.
Python Programming |S.Y. ECS - B 67 Electronics and Computer Science, PVPIT Budhgaon # Append contents into a file with open("file1.txt", "a") as file: file.write("I am fine.") # Read and print all lines of the file with open("file1.txt", "r") as file: print(file.readlines()) Result:
68.
Python Programming |S.Y. ECS - B 68 Electronics and Computer Science, PVPIT Budhgaon 10. b. Create a text file and write the string “abcdefghijklmnopqrstuvwxyz” into it. Read the string and print it in reverse order. Python Code: # File, reverse the string str = "abcdefghijklmnopqrstuvwxyz" # Write the string into a file with open("file2.txt", "w") as file: file.write(str) # 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) Result: