├── system_time.py ├── lamda_add_multiply.py ├── push_in_stack.py ├── unfunc panda lcm.py ├── check_PANDA_VERSION.py ├── panda series.py ├── sort_files_by_date.py ├── python-version.py ├── unfc log numpy.py ├── numpy_reshape_arr_1D_t0_3D.py ├── sum_of_all_num_of_list.py ├── Numpy arr_shape.py ├── numpy_permutation.py ├── ufunc products_numpy.py ├── calender.py ├── find_vowel.py ├── numbers-of-days-between.py ├── panda_dataframe.py ├── current__date_time.py ├── body_mass__index.py ├── color_present_in_c1_but_not_in_c2.py ├── height_to-cm.py ├── even_number_from_list.py ├── time_to_second.py ├── tuple_sorting_lambda.py ├── Lcm.py ├── max_of_three.py ├── linear_search.py ├── Gcd.py ├── binary_search.py └── README.md /system_time.py: -------------------------------------------------------------------------------- 1 | import time 2 | print() 3 | print(time.ctime()) 4 | print() 5 | -------------------------------------------------------------------------------- /lamda_add_multiply.py: -------------------------------------------------------------------------------- 1 | r=lambda a:a+15 2 | print(r(10)) 3 | r=lambda x,y:x*y 4 | print(r(12,4)) 5 | -------------------------------------------------------------------------------- /push_in_stack.py: -------------------------------------------------------------------------------- 1 | stack=[] 2 | stack.append(1) 3 | stack.append(2) 4 | stack.append(3) 5 | print(stack) 6 | -------------------------------------------------------------------------------- /unfunc panda lcm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | arr = np.array([3,6,9]) 3 | x=np.lcm.reduce(arr) 4 | print(x) 5 | -------------------------------------------------------------------------------- /check_PANDA_VERSION.py: -------------------------------------------------------------------------------- 1 | #check panda version 2 | #import pandas libary 3 | import panda as pd 4 | print(pd.__version__) 5 | -------------------------------------------------------------------------------- /panda series.py: -------------------------------------------------------------------------------- 1 | #series using pandas 2 | import pandas as pd 3 | a=[1,7,2] 4 | myvar = pd.series(a) 5 | print(myvar) 6 | -------------------------------------------------------------------------------- /sort_files_by_date.py: -------------------------------------------------------------------------------- 1 | import os 2 | files = glob.glob("*.txt") 3 | files.sort(key=os.path.gettime) 4 | print("\n".join(files)) 5 | -------------------------------------------------------------------------------- /python-version.py: -------------------------------------------------------------------------------- 1 | import sys 2 | print("python version") 3 | print(sys.version) 4 | print("version info.") 5 | print(sys.version_info) 6 | -------------------------------------------------------------------------------- /unfc log numpy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | arr = np.arrange(1,10) 3 | print(np.log2(arr)) 4 | print(np.log10(arr)) 5 | print(np.log(arr)) 6 | -------------------------------------------------------------------------------- /numpy_reshape_arr_1D_t0_3D.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | arr=np.array([1,2,3,4,5,6,7,8,9,12,3,4]) 3 | newarr=arr.reshape(2,3,2) 4 | print(newarr) 5 | -------------------------------------------------------------------------------- /sum_of_all_num_of_list.py: -------------------------------------------------------------------------------- 1 | def sum(numbers): 2 | total=0 3 | for x in numbers: 4 | total+=x 5 | return total 6 | print(sum((2,3,4,5))) 7 | -------------------------------------------------------------------------------- /Numpy arr_shape.py: -------------------------------------------------------------------------------- 1 | #code for change shape of array 2 | #import numpy as a libary 3 | import numpy as np 4 | arr=np.array([[1,2,3,4],[5,6,7,8]]) 5 | print(arr.shape) 6 | -------------------------------------------------------------------------------- /numpy_permutation.py: -------------------------------------------------------------------------------- 1 | #numpy permutations 2 | from numpy import random 3 | import numpy as np 4 | arr = np.array([1,2,3,4,5,6]) 5 | print(random.permutataion(arr)) 6 | -------------------------------------------------------------------------------- /ufunc products_numpy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | arr1 = np.array([1,2,3,4]) 3 | arr2 = np.array([5,6,7,8]) 4 | newarr = np.product([arr1,arr2],axis=1) 5 | print(newarr) 6 | -------------------------------------------------------------------------------- /calender.py: -------------------------------------------------------------------------------- 1 | #code for getting calender 2 | #import calender 3 | import calender 4 | y=int(input("input the year : ")) 5 | m=int(input("input the month :")) 6 | print(calender.month(y,m)) 7 | -------------------------------------------------------------------------------- /find_vowel.py: -------------------------------------------------------------------------------- 1 | #find vowel 2 | def is_vowel(char): 3 | #using function 4 | all_vowels ='aeiou' 5 | return char in all_vowels 6 | #checking vowel 7 | print(is_vowel('c')) 8 | -------------------------------------------------------------------------------- /numbers-of-days-between.py: -------------------------------------------------------------------------------- 1 | #numbers of day between 2 | from dateline impport dateline 3 | f_date = date(20025,7,2) 4 | l_date = date(2015,7,6) 5 | delta = l_date - f_date 6 | print(delta.days) 7 | -------------------------------------------------------------------------------- /panda_dataframe.py: -------------------------------------------------------------------------------- 1 | #panda dataframe 2 | import pandas as pd 3 | data={ 4 | "calories":[420,380,390], 5 | "duration":[50,40,20] 6 | } 7 | myvar=pd.DataFrame(data) 8 | print(myvar) 9 | -------------------------------------------------------------------------------- /current__date_time.py: -------------------------------------------------------------------------------- 1 | #current date and time 2 | #use this code 3 | import datetime 4 | now = datetime.datetime.now() 5 | print("current date and time:") 6 | print(now.strftime("%Y-%m-%d %H:%M::%S")) 7 | -------------------------------------------------------------------------------- /body_mass__index.py: -------------------------------------------------------------------------------- 1 | #code for calculating bmi of your body 2 | height = float(input("enter your height")) 3 | weight = float(input("enter your weight")) 4 | print("your body mass index is:",round(weight/(height*height),2)) 5 | -------------------------------------------------------------------------------- /color_present_in_c1_but_not_in_c2.py: -------------------------------------------------------------------------------- 1 | #find color present in color1 but not in color2 2 | color_list_1 = set(["white","black","red"]) 3 | color_list_2 = set(["white","black"]) 4 | print(color_list_1.difference(color_list_2)) 5 | -------------------------------------------------------------------------------- /height_to-cm.py: -------------------------------------------------------------------------------- 1 | #height to cm conveter 2 | print("input your height") 3 | h_ft = int(input("feet: ")) 4 | h_inch = int(input("inches:")) 5 | h_inch=+ h_ft*12 6 | h_cm = round(h_inch*2.54,1) 7 | print("your height is %d cm" % h_cm) 8 | -------------------------------------------------------------------------------- /even_number_from_list.py: -------------------------------------------------------------------------------- 1 | #find ecen number from list 2 | def is_even_number(l): 3 | enum =[] 4 | for n in l: 5 | if n%2==0: 6 | enum.append(n) 7 | return enum 8 | print(is_even_number([1,2,3])) 9 | -------------------------------------------------------------------------------- /time_to_second.py: -------------------------------------------------------------------------------- 1 | days = int(input("input days")) 2 | hours = int(input("enter hours")) 3 | minutes = int(input("enter minutes")) 4 | second = int(input("enter seconds")) 5 | time = days+hours+minutes+second 6 | print("the amount of seconds",time) 7 | -------------------------------------------------------------------------------- /tuple_sorting_lambda.py: -------------------------------------------------------------------------------- 1 | subject_marks =[('english',66),('science',90),('maths',98)] 2 | print("original list of tuples") 3 | print(subject_marks) 4 | subject_marks.sort(key=lambda x:x[1]) 5 | print("\nSorting the list of tuples") 6 | print(subject_marks) 7 | -------------------------------------------------------------------------------- /Lcm.py: -------------------------------------------------------------------------------- 1 | #code for Lcm 2 | #using function with parameters 3 | def lcm(x,y):: 4 | if x>y: 5 | z=x 6 | else: 7 | z=y 8 | while(True): 9 | #using while loop 10 | if((z % x ==0) and (z%y==0)): 11 | lcm=z 12 | break 13 | z+=1 14 | return lcm 15 | -------------------------------------------------------------------------------- /max_of_three.py: -------------------------------------------------------------------------------- 1 | #find max of three 2 | #first find max of two 3 | #using function with parameters 4 | def max_of_two(x,y): 5 | #usimg conditional statements 6 | if x>y: 7 | return x 8 | return y 9 | def max_of_three(x,y,z): 10 | return max_of_two(x,max_of_two(y,z)) 11 | print(max_of_three(3,6,7)) 12 | -------------------------------------------------------------------------------- /linear_search.py: -------------------------------------------------------------------------------- 1 | #linear search 2 | #using function 3 | def linearsearch(array,n,x): 4 | #used for loop 5 | for i in range(0,n): 6 | if(array[i]==x): 7 | return i 8 | return -1 9 | #given value 10 | array =[1,2,5,4,7,5] 11 | x=1 12 | n=len(array) 13 | result = linearsearch(array,n,x) 14 | if(result == -1): 15 | print("element not found") 16 | else: 17 | print("element found at index: ",result) 18 | -------------------------------------------------------------------------------- /Gcd.py: -------------------------------------------------------------------------------- 1 | #code for gcd 2 | def gcd(x,y): 3 | gcd=1 4 | #used conditional statement 5 | if x%y==0: 6 | return y 7 | #used for loop 8 | for k in range(int(y/2),0,-1): 9 | #using conditional 10 | if x%k==0 and y%k==0: 11 | gcd =k 12 | break 13 | return gcd 14 | 15 | print(gcd(12,15)) 16 | print(gcd(4,6)) 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /binary_search.py: -------------------------------------------------------------------------------- 1 | #code for binary search 2 | def binarySearch(array,x,low,high): 3 | #using while loop 4 | while low array[mid]: 10 | low =mid+1 11 | else: 12 | high=mid-1 13 | return -1 14 | #given array 15 | array=[3,4,5,6,7,8] 16 | x=4 17 | result=binarySearch(array,x,0,len(array)-1) 18 | if result!=-1: 19 | print("element is present at index"+str(result)) 20 | else: 21 | print("not found") 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python-30 2 | # Python Practice Programs 3 | 4 | 5 | Welcome to the repository of Python Practice Programs! This collection includes 30 Python scripts designed to help you improve your programming skills and understand various concepts in Python. Each program focuses on different topics and challenges, allowing you to practice and reinforce your knowledge. 6 | 7 | 8 | ## Introduction 9 | 10 | Python is a versatile programming language that is widely used for a variety of applications. Whether you're new to programming or looking to sharpen your skills, these practice programs will help you gain hands-on experience with essential concepts, algorithms, and data structures. 11 | 12 | ## Installation 13 | 14 | To run the programs, ensure that you have Python installed on your machine. You can download it from the official [Python website](https://www.python.org/downloads/). 15 | 16 | ### Prerequisites 17 | 18 | - Python 3.x 19 | - A code editor (e.g., VSCode, PyCharm, Sublime Text) 20 | - Command line interface (e.g., Terminal, Command Prompt) 21 | 22 | ## Program List 23 | 24 | Here’s a list of files included in this repository along with a brief description of each: 25 | 26 | 1. binary_search.py - Implements binary search algorithm to find an element in a sorted list. 27 | 2. body_mass_index.py - Calculates the Body Mass Index (BMI) based on weight and height. 28 | 3. calendar.py - Displays a calendar for a specified month and year. 29 | 4. check_PANDA_VERSION.py - Checks the version of the installed Pandas library. 30 | 5. color_present_in_c1_but_not_in_c2.py - Identifies colors present in one list but not in another. 31 | 6. current_date_time.py - Displays the current date and time. 32 | 7. even_number_from_list.py - Extracts and returns all even numbers from a given list. 33 | 8. find_vowel.py - Checks if a string contains any vowels. 34 | 9. gcd.py - Computes the greatest common divisor (GCD) of two numbers. 35 | 10. height_to_cm.py - Converts height from feet/inches to centimeters. 36 | 11. lambda_add_multiply.py - Demonstrates the use of lambda functions for addition and multiplication. 37 | 12. lcm.py - Calculates the least common multiple (LCM) of two numbers. 38 | 13. linear_search.py - Implements linear search algorithm to find an element in a list. 39 | 14. max_of_three.py - Finds the maximum of three given numbers. 40 | 15. numbers_of_days_between.py - Calculates the number of days between two dates. 41 | 16. numpy_arr_shape.py - Displays the shape of a NumPy array. 42 | 17. numpy_permutation.py - Generates permutations of a given list using NumPy. 43 | 18. numpy_reshape_arr_1D_to_3D.py - Reshapes a 1D NumPy array into a 3D array. 44 | 19. pandas_series.py - Demonstrates the creation and manipulation of a Pandas Series. 45 | 20. pandas_dataframe.py - Illustrates how to work with a Pandas DataFrame. 46 | 21. push_in_stack.py - Implements a stack and allows pushing elements onto it. 47 | 22. python_version.py - Displays the current version of Python. 48 | 23. sort_files_by_date.py - Sorts files in a directory based on their creation or modification date. 49 | 24. sum_of_all_num_of_list.py - Calculates the sum of all numbers in a given list. 50 | 25. system_time.py - Displays the system time in HH:MM:SS format. 51 | 26. time_to_second.py - Converts time in HH:MM:SS format to total seconds. 52 | 27. tuple_sorting_lambda.py - Sorts a list of tuples using lambda functions. 53 | 28. ufunc_products_numpy.py - Demonstrates the use of universal functions (ufuncs) in NumPy for multiplication. 54 | 29. unfunc_log_numpy.py - Shows how to apply the logarithm function on a NumPy array using ufuncs. 55 | 30. unfunc_panda_lcm.py - Utilizes Pandas functions to calculate the LCM of two numerical series. 56 | #Tech Stack 57 | ![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54) 58 | --------------------------------------------------------------------------------