Python Code:: RESULT: The Above Programs Are Solved Using Python Functions
Python Code:: RESULT: The Above Programs Are Solved Using Python Functions
EXERCISE:1
DATE: 29.11.21
AIM:
ALGORITHM:
STEP 1: Start
STEP 5: Stop.
FLOWCHART:
PYTHON CODE:
OOOUTPUT:
1
PALINDROME
EXERCISE:2
DATE: 29.11.21
AIM:
ALGORITHM:
STEP 2: A= num
4 till num = 0
FLOWCHART:
2
PYTHON CODE:
3
PRIME NUMBER
EXERCISE:3
DATE: 29.11 21
AIM:
ALGORITHM:
STEP 5: Stop.
FLOWCHART:
PYTHON CODE:
4
RESULT: The above program is solved using python functions.
FINDING YOUNGER AGE
EXERCISE:4
DATE: 29.11.21
AIM:
ALGORITHM:
STEP 1: Start
a is younger.
STEP 5: Stop.
FLOWCHART:
PYTHON CODE:
5
AVERAGE AGE OF 10 PLAYERS
EXERCISE:5
DATE: 29.11.21
AIM:
ALGORITHM:
STEP 1: Enter n = 10
STEP 2: Enter p = 1
STEP 3: Sum = 0
STEP 6: P = 1+P
FLOWCHART:
PYTHON CODE:
6
FACTORIAL
EXERCISE:6
DATE: 29.11.21
AIM:
ALGORITHM:
7
STEP 4: Fact = fact*i, i=i+1
STEP 5: Stop.
FLOWCHART:
PYTHON CODE:
FIBONACCI SERIES
EXERCISE:7
DATE: 29.11.21
AIM:
ALGORITHM:
8
STEP 4: Assign i=0
STEP 7: I=I-1
STEP 8: Stop
FLOWCHART:
PYTHON CODE:
9
SUM OF SQUARES OF FIRST N NATURAL NUMBERS
EXERCISE:8
DATE: 29.11.21
AIM:
ALGORITHM:
STEP 1: Start
STEP 3: Enter n
10
STEP 4: If i>n go to step 7, else go to step 4
STEP 5: Sum=sum+i
STEP 6: I=I+1
FLOWCHART:
PYTHON CODE:
11
ELECTRICITY BILL GENERATOR
EXERCISE:9
DATE: 4.12.21
AIM:
ALGORITHM:
STEP 1: Start
STEP 3: If a<50
else
go to step 4
STEP 4: If a<=100
else
go to step 5
STEP 5: If a<2000
else
STEP 8: Stop.
12
FLOWCHART:
PYTHON CODE:
13
EXERCISE:10
DATE: 4.12.21
AIM:
ALGORITHM:
STEP 1: Start
STEP 5: Using if condition to compare the length of a string with count, if true print
else
STEP 6: Stop
PYTHON CODE:
14
LENGTH OF THE NUMBER USING LOOP
EXERCISE:11
DATE: 4.12.21
AIM:
ALGORITHM:
STEP 2: Using a while loop, get each digit of the number and increment the count
STEP 4: Stop.
FLOWCHART:
PYTHON CODE:
15
STUDENT’S RANK STATUS
EXERCISE:12
DATE: 7.12.21
AIM:
Write a program to input marks of 5 subjects (Physics, Chemistry, English, Maths, Computer Science) for 5
students. Display rank of each student also result of total marks, percentage, rank in a class. The rank is
categorised as fail(mark<40%), pass & third grade (41% - 55%) second grade (56% to 65%), First grade (66% to
75%) Distinction (76% to 90%) and extraordinary (91% to 100%).
ALGORITHM :
Step 1: input marks of five subjects in some variable say phy,chem,bio,math and comp
Step 2: calculate percentage using formula per = (phy + chem + bio + math + comp)/5.0; carefully notice i have
divided sum with 5.
Step 5: if percentage is not more than 90, then check remaining conditions mentioned and print grade
PYTHON CODE:
16
MULTIPLICATION TABLE
EXERCISE:13
DATE: 7.12.21
AIM:
Write a program to get a number and print the multiplication table of it.
ALGORITHM :
• Input the end value until which the table has to be generated.
PYTHON CODE:
17
SWAPPING TWO NUMBERS
EXERCISE:14
DATE:7.12.21
AIM:
AIM:
ALGORITHM:
STEP 3: temp = n1
STEP 4: n1=n2
STEP 5 : n2=temp
PYTHON CODE:
18
TRANSPOSE OF A MATRIX
EXERCISE:15
DATE: 11.12.21
AIM:
ALGORITHM:
Step 1: start
Step 4: the element in the i th row and j th coloum will be placed at j th row and i th coloum.
Step 5: stop
PYTHON CODE:
19
DIAGONAL ELEMENTS IN A MATRIX
EXERCISE:16
DATE: 11.12.21
AIM:
ALGORITHM:
STEP 1: Start
STEP 4: Stop
PYTHON CODE:
20
LENGTH OF THE GIVEN STRING
EXERCISE:17
DATE: 21.12.21
AIM:
ALGORITHM:
STEP 2: Now the first character of text (that is,’c’) gets copied to ch variable
and program flow goes inside the loop, and the value of tot gets
incremented by 1
STEP 4: Now second character of text (that is,’o’) gets copied to ch, and
program flow goes inside the loop and the value of tot again gets
incremented by 1
STEP 5: This process continues, until each and every character of text gets
sanned.
STEP 6: In this way, after exiting from the loop, the variable tot holds the
PYTHON CODE:
21
FINDING THE VOWELS
EXERCISE:18
DATE: 21.12.21
AIM:
ALGORITHM:
STEP 2: Inside the for loop, we are using if statement to chack whether the
character is a, e, i, o, u, a, e, i, o, u.
STEP 3: If true, increment the vowels value otherwise, skip that character.
PYTHON CODE:
22
TO CHECK IF THE STRING CONTAINS ANY SPECIAL CHARACTERS
EXERCISE:19
DATE: 21.12.21
AIM:
To check whether the given string contains special characters or not using python.
ALGORITHM:
STEP 1: We will first import the required packege from the python library
STEP 2: Then, check the presence of special characters and pass it into the
PYTHON CODE:
23
TO SPLIT AND JOIN THE STRING
EXERCISE:20
DATE: 21.12.21
AIM:
ALGORITHM:
STEP 1: Start
STEP 9: Stop.
PYTHON CODE:
24
COUNT ALL DIGITS, LETTERS AND SPECIAL CHARACTERS
EXERCISE:21
DATE: 27.12.21
AIM:
ALGORITHM:
Isalpha () is the first statement is to check whether the character is an alphabet or not
If true, alphabets value incremented.
Isdigit() is the second statement checks whether the character is digit or not.
If true, digits value is incremented.
Otherwise, special characters value is incremented .
PYTHON CODE:
25
REPLACE EACH SPECIAL CHARACTER WITH # SYMBOL
EXERCISE:22
DATE: 27.12.21
AIM:
ALGORITHM:
STEP 1: start
STEP 2: Use the string.punctuation constant to get the list of all punctuations.
STEP 4: Use string function replace () to replace the current symbol in a string with #
STEP 4: Stop
PYTHON CODE:
26
CREATE A STRING MADE OF 1ST, MIDDLE AND LAST CHARACTER
EXERCISE:23
DATE:27.12.21
AIM:
To create a string made of first, middle and last character of already entered string in python
ALGORITHM:
STEP 1: Start
STEP 2: Use string indexing to get the character present at the given index.
STEP 3: Use str [0] to get the first character of the string and add it to result variable
STEP 4: Next, get the middle character’s index by dividing string length by 2.
X = len(str)/2
STEP 5: Use str[x] to get the middle character and add it to the result variable
STEP 6: Use str[len[(str1)-1] to get the last character of the string and add it to the result variable
PYTHON CODE:
27
LENGTH OF THE LIST
EXERCISE:24
DATE:
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Input the list given by the user and store it in list1
STEP 3: Find the length of the given list using len() function
STEP 5: Stop
PYTHON CODE:
28
TO CONCATENATE TWO LISTS
EXERCISE:25
DATE: 3.1.22
AIM:
ALGORITHM:
STEP 1: Start
STEP 2: Input the lists entered by the user and store it in list1 and list2.
STEP 5: Stop.
PYTHON CODE:
29
TO LIST OUT THE EVEN NUMBERS IN THE LIST
EXERCISE:26
DATE: 3.1.22
AIM:
To list out only the even numbers that are present in the given list using python.
ALGORITHM:
STEP 1: Start
PYTHON CODE:
30
TO FIND THE 2ND SMALLEST NUMBER IN THE LIST
EXERCISE:27
DATE: 4.1.22
AIM:
To find the second smallest number in the given list without using any methods using python.
ALGORITHM
STEP 1: Get the list from the user and declare a variable for it.
STEP 2: Declare n the initial value, and use for loop every element in the list is been traversed
STEP 3: Use the bubble sort method to arrange the list in ascending order.
STEP 4: Print the 1st index value as it gives the second smallest number.
PYTHON CODE:
31
TO CONVERT A LIST OF MULTIPLE INTERGERS INTO SINGLE INTEGER
EXERCISE:28
DATE: 4.1.22
AIM:
To join the numbers in the list given by the user using python
ALGORITHM:
STEP 1: Start
STEP 2: Give the input statement to get the list values from the user
STEP 3: Use the for loop and atlast give the print statement to join the two lists
STEP 4: Stop
PYTHON CODE:
32
INTERCHANGE 1ST AND LAST ELEMENTS OF A LIST
EXERCISE:29
DATE: 24.1.22
AIM:
To interchange first and last elements of a given list and display the list using python.
ALGORITHM:
STEP 2: Find the length of the given list using Len () function.
STEP 4: Equate the first element of the list with the last element of the list.
PYTHON CODE:
33
TO FIND THE LENGTH OF THE DICTIONARY
EXERCISE:30
DATE: 25.1.22
AIM:
ALGORITHM:
34
CONCATENATE DICTIONARIES
EXERCISE:31
DATE: 25.1.22
AIM:
Write a Python program to concatenate following dictionaries to create a new one.
ALGORITHM:
• Declare and initialize three dictionaries with some key-value pairs.
• Using for loop each element is traversed in the three dictionaries.
• Use the update () function to add the key-value pair from the second dictionary to
the first dictionary.
• Print the final dictionary.
PYTHON CODE:
35
MAXIMUM AND MINIMUM VALUES IN A DICTIONARY
EXERCISE:32
DATE: 25.1.22
AIM:
Write a Python program to get the maximum and minimum value in a dictionary.
ALGORITHM:
Take the number of elements to be entered in the dictionary from the user.
An empty dictionary is created.
Take a key-value pair from the user and store it in separate variables.
Declare a dictionary and initialize it to an empty dictionary.
Use the update () function to add the key-value pair to the dictionary.
Using the max () and min () function the maximum and minimum values are calculated.
Print the final dictionary, maximum value, minimum value.
PYTHON CODE:
36
SUM OF THE LIST
EXERCISE:33
DATE: 14.2.22
AIM:
ALGORITHM:
PYTHON CODE:
37
GEOMETRIC MEAN OF GIVEN NUMBER
EXERCISE:34
DATE: 14.2.22
AIM:
To calculate the geometric mean of the given number using python functions.
ALGORITHM:
STEP 1: First I have given the variable name as n and used the int datatype to get the number from
the user
STEP 3: Next comes the if statement for n is smaller the 2, then the function will return the value 1
STEP 4: Else it will return the geometric sum value for the given number
STEP 5: Then at last I’ve given the print statement to print the value
PYTHON CODE:
38
PERMUTATIONS OF GIVEN STRING
EXERCISE:35
DATE: 21.2.22
AIM:
ALGORITHM:
STEP 1: Take string as the input from the user and store it in a variable str to permute the given
string
STEP 3: Inside the function if the length of the string is equal to zero then call the permutation
function
STEP 4: Assign the list to store the permutated string from index one to the last index and assign a
new empty list
STEP 5: Using for loop every value of i is traversed in the range of the string from index zero to the
length of the string stored in the list.
STEP 6: Again, using the for loop every value of j is traversed in the range of the string index zero to
the length of the actual string entered by the user
STEP 8: Now update the string stored in the new variable to the already created empty list
STEP 9: Call the function recursively with the argument of the appended list and print the
permutated string
PYTHON CODE:
39
POSSIBLE STRINGS BY PLACING SPACES
EXERCISE:36
DATE: 21.2.22
AIM:
To write a python program to print all possible strings made by placing spaces using python
functions.
ALGORITHM:
STEP 1: Take a string input from the user and store it in a variable str for finding permutated strings
with spaces between them
STEP 3: Declare the python function to find the sequences of the string
STEP 4: Assign a variable to store the length of the string entered and assign another variable(opsize)
to store the power of (2,len(str-1))
STEP 5: using a for loop every element in the range of opsize and for every value of j in the range of
value of the length of the string print the string of j
STEP 6: If the element of opsize and (1<<j) is true print the end statement
STEP 7: If driver code is true then the sequences of the string is printed
PYTHON CODE:
40
NO REPETITION OF PERMUTATIONS
EXERCISE:37
DATE:21.2.22
AIM:
To write a function to print all permutations of given string such that no permutation is repeated in
output.
ALGORITHM:
STEP 1: Take string as the input from the user and store it in a variable str to permute the given
string
STEP 3: Inside the function if the length of the string is equal to zero then call the permutation
function
STEP 4: Assign the list to store the permutated string from index one to the last index and assign a
new empty list
STEP 5: Using for loop every value of i is traversed in the range of the string from index zero to the
length of the string stored in the list.
STEP 6: Again, using the for loop every value of j is traversed in the range of the string index zero to
the length of the actual string entered by the user
STEP 8: If the new variable is not in the already created empty list, update the string stored in the
new variable to the already created empty list. This is done to avoid duplicates
STEP 9: Call the function recursively with the argument of the appended list and print the
permutated string.
PYTHON CODE:
41
RECURSION
EXERCISE:38
DATE: 21.2.22
AIM:
We can define the sum from 1 to x (i.e., 1 + 2 + ... + x) recursively as follows for integer x ≥
1:
1, if x = 1x + sum from 1 to x-1 if x > 1. Complete the following Python program to
compute the sum 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 recursively
ALGORITHM:
Take a list as the input from the user and store it in a variable A to find the maximum
recursions of the string
Define a python function to find the sum from one to x
If the length of the list entered by the user is equal to one call the function recursively with
the argument of A [0] then call off the function recursively with an argument to find the
maximum value of the last index of the list
If driver code is true then print the python function
PYTHON CODE:
42
FIBONACCI NUMBERS
EXERCISE:39
DATE: 22.2 22
AIM:
Revise the Fibonacci program so that it asks the user for which Fibonacci number he or
she wants. Then use this value to instead of 6 in the program. Use your program to
compute the 10th, 20th, 30th and 40th Fibonacci numbers
ALGORITHM:
Take a list as the input from the user and store it in a variable A to find the maximum
recursions of the string
Define a python function to find the sum from one to x
Take a number from the user and store it in a variable n to find the Fibonacci numbers
Declare a python function to find the nth Fibonacci number
If n is less than or equal to zero print it is an incorrect input
Else if n is equal to one call the function recursively with an argument zero
Else if n is equal to two call the function recursively with an argument one
Else call the function recursively with an argument by adding the last and the second last
input by the user
Print the Fibonacci numbers
PYTHON CODE:
43
COUNT THE NUMBER OF DIGITS
EXERCISE:40
DATE:
AIM:
We can determine how many digits a positive integer has by repeatedly dividing by 10 (without
keeping the remainder) until the number is less than 10, consisting of only 1 digit. We add 1 to this
value for each time we divided by 10
ALGORITHM:
Take floating-point number as the input from the user and store it in the variable num
Declare a python function to count the number of digits
To count the number of digits entered by the user
If the value entered by the user is less than ten call the function recursively with an
argument one
Else call off the function recursively with an argument one adding the count of n divided by
ten
Print the number of digits
PYTHON CODE:
44
MAXIMUM INTERGER USING RECURSION
EXERCISE:41
DATE: 22.2.22
AIM:
Write a recursive Python function that has a parameter representing a list of integers and returns
the maximum stored in the list. Thinking recursively, the maximum is either the
first value in the list or the maximum of the rest of the list, whichever is larger.
ALGORITHM:
•Base case: If the remaining array is of length 1, return the only present element i.e., arr[0]
•Recursive call: If the base case is not met, then call the function by passing the array of one size less
from the end, i.e. from arr[0] to arr[n-1].
•Return statement: At each recursive call (except for the base case), return the maximum of the last
element of the current array (i.e., arr[n-1]) and the element returned from the previous recursive
call. return max(arr[n-1], recursive_function(arr, n-1));
•Print the returned element from the recursive function as the maximum element
PYTHON CODE:
45
OCCURENCES OF EACH WORD
EXERCISE:42
DATE:22.2.22
AIM:
ALGORITHM:
STEP 5: Using for loop every element in the file is traversed and splitted.
STEP 6: If the traversed element not found in empty list update the element into the empty list using
append() function.
STEP 8: If every element given is a word ,the repeated words are counted using count() function and
stored in temporary variable.
STEP 9: The element traversed and the count of the words are printed.
PYTHON CODE:
46
TOTAL NUMBER OF VOWELS
EXERCISE:43
DATE:22.2.22
AIM:
ALGORITHM:
Take the input file name from the user with the location of the file .
STEP 4: Using for loop every character in in the file opened is read by traversing it.
STEP 5: If the given character is a vowel,then the count of total is increased for every vowel read in
the file.
STEP 6: The file is closed using close() function and the total number of vowels is printed.
PYTHON CODE:
47
COPY THE SENTENCE FROM ONE FILE TO ANOTHER
EXERCISE:44
DATE:22.2.22
AIM:
To copy the sentence from one text file to another text file.
ALGORITHM:
STEP 1: Input the filename and the location of the file and open it using open() function.
STEP 2: Open another file to copy the text from the first file and name the file as f1.
STEP 3: Using for loop every line in the file is traversed and the file1 is scripted to write mode.
STEP 4: Using open() function the file1 is opened and the text from file is copied to file1.
PYTHON CODE:
48
FIND THE COMMON WORDS IN A FILE
EXERCISE:45
DATE:22.2.22
AIM:
ALGORITHM:
STEP 1: Open the text file sampletxt using open() function with f as file object in r+ mpode.
STEP 2:Using the read() function read the file using reader object a.
STEP 5: Loop through b and if a word is not present in d, store it in d with value 1, else if the word
is already present in d increase its value by 1.
STEP 6:Loop through d and print each key, value pair if the value of the key is greater than 5 to find
the most common words in the text file.
PYTHON CODE:
49
TOTAL NUMBER OF LINES,WORDS AND CHARACTERS IN A FILE
EXERCISE:46
DATE:22.2.22
AIM:
To find the total number of lines, words and characters present in a file.
ALGORITHM:
Input the filename and location of the file and open the file using open() function.
STEP 3: The strip() function is used to copy the string by removing both the leading and the trailling
characters to form a line.
STEP 4: To form words the lines formed is split using split() function.
STEP 5: For every line in the file ,the count is increased and stored in a variable.
STEP 6: For every word in the file,the count is increased and stored in a variable added to the length
of the words.
STEP 7: For every character in the file,the count is increased and stored in a variable added to the
length of the line in the file.
STEP 8: The file is closed using close() function and the no of lines, no of words and no of characters
is printed for the text in the file.
PYTHON CODE:
50
PYTHON PROJECT
WEATHER FORCASTING
ABSTRACT:
Weather simply refers to the condition of air on the earth at a given place and time. Weather
forecasting entails predicting how the present state of the atmosphere will change. To predict the
conditions of the atmosphere for a given location Weather Forecasting is used. The weather forecast
can be done in many ways like using the previous data or analysing the current clouds.
LOCATION SEARCHING: We can search for any location and know the weather of searched
locations. To provide the ease of searching cities/ states to user, we’ve integrated open map
library and worldwide map and with the use of this user can easily search weather of
anywhere.
WEATHER FORECASTING PREDICTION REPORTS: In this application, the user is able to view
the current weather details with all the weather parameters like Temperature, sky
description, date and time of the given location from which the user can easily check the
current status of weather parameters. Firstly, the data is trained. For this prediction, we will
be using google to get the data. For the project we will using Python, Pandas, Python idle and
Jupyter Notebook. We made a model to predict the weather using some selected input
variables collected from Google.
MODULES USED:
Tkinter import *
PIL import ImageTk, Image
Datetime
Suntime
Bs4 import beautifulSoup
Sys
Requests
Datetime import date
geopy.geocoders import Nominatim
51
PYTHON CODE:
52
OUTPUT:
53
54