Program to check if the number belongs to the fibonacci sequence. N = int(input("Enter a Number : ")) f3 = 0 f1 = 1 f2 = 1 if(N == 0 or N == 1): print("The Given Number belongs to fibonacci series") else: while(f3 < N): f3 = f1 + f2 f1 = f2 f2 = f3 if(f3 == N): print("The Given Number belongs to fibonacci series") else: print("The Given Number does not belong to fibonacci series") Progrma to solve quadratic equations. import math def findroot(a,b,c): dis_form = b * b - 4 * a * c sqrt_val = math.sqrt(abs(dis_form)) if dis_form > 0: print("Real and Different Roots ") print((-b + sqrt_val) / (2 * a)) print((-b - sqrt_val) / (2 * a)) elif dis_form == 0: print("Real and Same Roots") else: print("Complex Rots") print(-b / (2 * a), "+ i", sqrt_val) print(-b / (2 * a), "- i", sqrt_val) a = int(input("Enter The Value Of a : ")) b = int(input("Enter The Value Of b : ")) c = int(input("Enter The Value Of c : ")) if a == 0: print(" Input Correct quadratic") else: findroot(a, b, c,) program to find the sum of the natural numbers. N = int(input("Enter a Number : ")) dup1 = N if N < 0: print("please Enter a Positive Number") else: sum = 0 while(N > 0): sum += N N -= 1 print("Sum of the",dup1," natural numbers is",sum) program to display a multiplication table N = int(input("Enter a Number : ")) print("The Table Of" ,N) for i in range(1,11): print(N,"*",i,"=",i*N) Program to check if the number is prime number or not. num = int(input("Enter The Number : ")) flag = False if num == 1: print(num,"is not prime number") elif num > 1: for i in range(2,num): if(num % i) == 0: flag = True break if flag: print(num,"is not prime number") else: print(num,"is prime number") Program To implement the Sequential search. from array import * def linear_search(A, N, KEY): for i in range(0, N): if (A[i] == KEY): return i return -1 A = array('i',[]) N = int(input("Enter The Total Number Of Elements Of Array : ")) print(f"Enter {N} integer elements of an array") for i in range(N): A.append(int(input())) KEY = int(input("Enter the key element to be searched : ")) result = linear_search(A, N, KEY) if (result == -1): print("Element not found") else: print("Element found") program to create simple calculator functions def calculator (x, i, j): switcher = { 1: (i + j), 2: (i - j), 3: (i / j), 4: (i % j), } print(switcher.get(x,"wrong input")) print(".................SIMPLE CALCULATOR..............") print("1.ADDITION") print("2.SUBTRACTRACTION") print("3.MULTIPLICATION") print("4.DIVISION") x = input ("Please enter your operation :-->") i = int(input("Please enter your first number :-->")) j = int(input("Please enter your second numberc :-->")) calculator (int(x), int(i), int(j)) program to Explore string functions str1 = input("Enter the first string :") str2 = input("Enter the second string :") print("Conversion of the",str1,"in uppercase :",str1.upper()) print("Conversion of the",str2,"in lowercase :",str2.lower()) print("Swapcase of the ",str1,"is ",str1.swapcase()) print("The cased version of the",str2,"is",str2.title()) print("The string replecement of first string",str1,"to",str1.replace(str1,str2)) string = "python is awesome" capitalize_string = string.capitalize() print("The string",string,"is capitalized to",capitalize_string) substring = "is" count = string.count(substring) print("The count of the given string :",count) name = "bcacollege,nidsoshi" if name.isalpha()==True: print("All characters are alphabets") else: print("All characters are not alphabets") print("Maximun is :",max(1,2,3,5,4,6,)) num = [1,3,4,5,6,7,8,9,10,11] print("The maximum number in given array is :",max(num)) print("Length of first string :",len(str1)) program to implement selection sort. from array import* N = int(input("Enter the size of the array :")) A = array('i',[]) print("Enter the array elements :") for i in range(N): A.append(int(input())) for i in range(0,len(A)-1): for j in range(i+1,len(A)): if A[i] > A[j]: temp = A[i] A[i] = A[j] A[j] = temp print("The content of the array after sorting is :") for i in range(N): print(A[i]) program to implement stack def create_stack(): stack = list() return stack def Isempty(stack): return len(stack) == 0 def push(stack,n): stack.append(n) print("pushed element",n) def pop(stack): if (Isempty(stack)): return "stack is empty" else: return stack.pop() def show(stack): print("The stack elements are ") for i in stack: print(i) stack = create_stack() push(stack,str(10)) push(stack,str(20)) push(stack,str(30)) push(stack,str(40)) show(stack) print("popped item "+pop(stack)) show(stack) program to read and write in to a file1. file1 = open("myfile.txt","w") L = ["This is Delhi \n","This is Paris \n","This is London \n"] file1.write("Hello \n") file1.writelines(L) file1.close() file1=open("myfile.txt","r+") print("output of Read Function is ") print(file1.read()) file1.seek(0) print("output of Write Function is ") print(file1.readline()) file1.seek(0) print("output of Readline Function is ") print(file1.readline()) file1.seek(0) print("output of Read(9) Function is ") print(file1.read(9)) file1.seek(0) print("output of Readline(9) Function is ") print(file1.readline(9)) file1.seek(0) print("output of Readlines Function is") print(file1.readlines()) file1.close() program to Demonstrate the usage of basic regular expressions. import re str="The rain in spain" x=re.findall("ai",str) print("Search of string 'ai': ",x) x=re.search("\s" ,str) print("The first white-space character is located in position : ",x.start()) x=re.split("\s",str,1) print("Split the string in the occurance of first white-space:",x) x=re.sub("\s","9",str) print("Each white-space is replaced with 9 digit: ",x) print("----------------------------------------------") x=re.findall("[a-m]",str) print("The letters in between a to m in the string:",x) x=re.findall("spain$",str) if(x): print("\n",str, ": Yes, this string ends with 'spain' word ") else: print("\n No match ") x=re.findall("^The",str) if(x): print("\n",str,": Yes, this string starts with 'The' word") else: print("\n No match") str1="The rain in spain falls mainly in the plain" x=re.findall("ai*",str1) print("\n All ai matching characters:",x) if(x): print("Yes, there is atleast one match") else: print("No match") x=re.findall("al{2}",str1) print("\n The string which contains 'all':",x) if(x): print("Yes, there is atleast one match") else: print("No match") str2="That will be 59 dollars" x=re.findall("\d",str2) print("\n Digits in the string:",x) x=re.findall("do...rs",str2) print("\n Dot metacharacter matches any character:",x) program to use of advanced regular expressions for data validation. import re def validate_password(password): regular_expression = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!#%*?&]{6,20}$" pattern = re.compile(regular_expression) valid = re.search(pattern, password) if valid: print("Password is valid.") else: print("Password is invalid.") list_of_passwords = ['Abc@123','abc@123', 'ABC@123','Abc@xyz','abc123','12@#$%Abc', 'Ab@1',"AAAAAbbbbbcccccc@#$%123456789"] for i in list_of_passwords: print(i,":"), validate_password(i) progran to demonstrate use of list. animal = ['Cat', 'Dog', 'Rabbit'] print("Old List : ",animal) animal.append ('Cow') print("Updated List : ",animal) language = ['Python','Java','C++','C'] print("Old List :",language) language.pop(3) print ("Updated List :",language) Vowels = ['e','i','u','o','a'] print("Old List : ",Vowels) Vowels.sort() print("Sorted List Assending Order :",Vowels) Vowels.sort(reverse=True) print("Sorted List in Descending Order :",Vowels) vowels = ['a','e','i','u'] print("Old List :",vowels) vowels.insert(3,'o') print("New List :",vowels) vowels.remove('a') print("Update List :",vowels) OS = ['Linux','Windows','Mac'] print("Old List :",OS) OS.reverse() print("New List :",OS) program to demonstrate use of dictionary thisdict = {'NAME':'vishal','PLACE':'Sankeshwar','USN':'1234567'} print("Dictionary Content :",thisdict) x = thisdict['PLACE'] print("Place is :",x) print("keys in dictionary are :") for x in thisdict: print(x) print("values in dictionary are :") for x in thisdict: print(thisdict[x]) print("Keys and values in the dictionary are : ") for x,y in thisdict.items(): print(x,":",y) print("Total items in the dictionary : ",len(thisdict)) thisdict['District'] = 'Belagavi' print("Added new item is = ",thisdict) thisdict.pop('PLACE') print("After removing a item in the dictionary : ",thisdict) del thisdict['USN'] print("After deleting a item in the dictionary : ",thisdict) thisdict.clear() print("Empty dictionary",thisdict) mydict = thisdict.copy() print("Copy of dictionary is = ",mydict) program to create SQLite Database and perform Operation on Table import sqlite3 conn = sqlite3.connect("test1.db") curs = conn.cursor() curs.execute("Create table tab3(id integer,name text)") curs.execute("insert into tab3(id,name) values(101,'Hari')") curs.execute("insert into tab3(id,name) values(102,'Ravi')") curs.execute("insert into tab3(id,name) values(103,'Shashi')") print("Displaying the tab3 table") curs.execute("select * from tab3") rows = curs.fetchall() for i in rows: print(i) curs.execute("update tab3 set name = 'Hari' where id = 101") curs.execute("delete from tab3 where id = 103") print("Displaying the tab3 table....After updating the tab3 table : ") curs.execute("select * from tab3") rows = curs.fetchall() for i in rows: print(i) curs.execute("drop table tab3") conn.commit() curs.close() conn.close() program to create a GUI using TKinter Module import tkinter as tk def show_entry_fields(): print("First Name : %s\nLast Name : %s"%(e1.get(),e2.get())) master = tk.Tk() #master.geometry("250x450") tk.Label(master,text="GUI",font=('times',24,'italic')).grid(row=0) tk.Label(master,text="Fist Name").grid(row=1) tk.Label(master,text="Last Name").grid(row=2) e1 = tk.Entry(master) e2 = tk.Entry(master) e1.grid(row=1,column=1) e2.grid(row=2,column=1) tk.Label(master,text="Select Gender : ",fg="blue").grid(row=3,column=0) R1=tk.Radiobutton(master,text="Male",value=1).grid(row=4,column=0,sticky=tk.W) R2=tk.Radiobutton(master,text="Female",value=2).grid(row=4,column=1,sticky=tk.W) tk.Label(master,text="Select Age",fg="blue").grid(row=5,column=0) tk.Spinbox(master,from_=18,to=25).grid(row=5,column=1) tk.Label(master,text="Select Subject",fg="blue").grid(row=6,column=0) tk.Checkbutton(master,text="Java").grid(row=7,column=0,sticky=tk.W) tk.Checkbutton(master,text="Python").grid(row=8,column=0,sticky=tk.W) tk.Label(master,text="Select District",fg="blue").grid(row=9,column=0) listbox = tk.Listbox(master) listbox.insert(1,"Belgaum") listbox.insert(2,"Banglore") listbox.insert(3,"Dharawad") listbox.insert(4,"Hubli") listbox.insert(5,"Mysore") listbox.insert(6,"Manglore") listbox.grid(row=10,column=1) tk.Button(master,text="QUIT",fg="red",bg="yellow",command=master.quit).grid(row=11,column=0,sticky=tk.W,pady=4) tk.Button(master, text="SHOW", fg="red", bg="yellow", command=show_entry_fields).grid(row=11, column=1,sticky=tk.W,pady=4) tk.mainloxop() program to demonstrate exception handling. try: print("TRY BLOCK") a =int(input("Enter a :")) b =int(input("Enter b :")) c = a/b except: print("EXCEPT BLOCK") print("We Cannot Divide By Zero") else: print("ELSE BLOCK") print("The Division Of a and b is : ",c) print("NO EXCEPTION") finally: print("FINALLY BLOCK") print("Out of EXCEPT,ELSE and FINALLY BLOCK") program to Draw Line Chart and Bar Chart using Matplotlib. import matplotlib.pyplot as plt import numpy as nmpi xpints = nmpi.array([12,10,20,50]) ypoints = nmpi.array([10,20,28,57]) plt.plot(xpints, ypoints) xpints = nmpi.array(['Apple','Doll','Cat','Duck']) ypoints = nmpi.array([23,45,68,30]) plt.bar(xpints, ypoints) plt.show() program to draw histograms andnd picharts using matplotlib. import matplotlib.pyplot as mlt student_performance = ["Excellet","Good","Average","Poor"] student_values = [15,20,40,10] mlt.pie(student_values,labels=student_performance,startangle=90,explode=[0.2,0.1,0,0],shadow=True,colors=["violet","indigo","blue","orange"]) mlt.show() #histogram type bar marks = [90,92,40,60,55,44,30,20,10,54,74,82] grade_interval = [0,35,70,100] mlt.title(".........STUDENT GRADES.........") mlt.hist(marks,grade_interval,facecolor = "black",rwidth=0.7,histtype="bar") mlt.xticks([0,35,70,100]) mlt.xlabel("PERCENTAGE") mlt.ylabel("NO OF STUDENTS") mlt.show() program to create Array using Numpy and perform operations on arrays. import numpy as np #creating an array array=np.array([4,3,2,1]) a=np.array([1,2,3,4]) print("Array elenents are",array) #minimum value of the array min_value = np.min(array) print("Minimum value is ",min_value) #mximum value of array max_value = np.max(array) print("Maximum value is ",max_value) #mean value of array mean = np.mean(array) print("Mean value is ",mean) #add each element with 10 array = array+10 print("add 10 to each element in the array",array) #multiply each array element wit 2 array = array*2 print("Multiply by 2 with in the array",array) #sorting the array sort=np.sort(array) print("Sorted Array in assending order : ",sort) print("Sorted Array in descending order : ",np.sort(array)[::-1]) #adding with function add=np.add(array,a) print("Adding",add) #substracting with function sub=np.subtract(array,a) print("Substracting ",sub) Program No.11: Program to Create DataFrameform Excel sheet using Pandas and Perform Operations on DataFrames. import pandas as pd #Create an EXCEL file "MY1 xlsx" and save it into your Project Path data = pd.read_excel('file.xlsx') print("\n displaying data from dataframes**\n") print (data) print("\n*OPERATING ON DATAFRAMES*\n") print("\n1 View the first few rows of the dataframos: ") print(data.head()) print("\n2. Number of rows and columns in the dataframes: ", end=" ") print (data. shape) print ("\n3 Filtered data (Age column < 20):") filtered_data = data[data['Age'] < 20] print (filtered_data) print("\n4. Sort dataframes based on 'Age' col in ascending order: ") sorted_data = data.sort_values(by = 'Age', ascending = True) print (sorted_data) print ("\n program closed. ")