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

Python Code:: RESULT: The Above Programs Are Solved Using Python Functions

The document contains 13 exercises involving algorithms and Python code to solve problems related to finding the greatest of two numbers, determining if a number is a palindrome or prime, calculating average age, factorial, Fibonacci series, sum of squares, electricity bill, anagram checking, number length, student rank and multiplication table. The algorithms use steps like input, calculation, comparison, output and loops. Python functions are used to code the algorithms and test the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Python Code:: RESULT: The Above Programs Are Solved Using Python Functions

The document contains 13 exercises involving algorithms and Python code to solve problems related to finding the greatest of two numbers, determining if a number is a palindrome or prime, calculating average age, factorial, Fibonacci series, sum of squares, electricity bill, anagram checking, number length, student rank and multiplication table. The algorithms use steps like input, calculation, comparison, output and loops. Python functions are used to code the algorithms and test the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

GREATEST OF TWO NUMBERS

EXERCISE:1

DATE: 29.11.21

AIM:

To find the greatest of two numbers using python

ALGORITHM:

STEP 1: Start

STEP 2: Input value for a

STEP 3: Input value for b

STEP 4: If a is greater than b, print a is greatest number else

Print b is the greatest number.

STEP 5: Stop.

FLOWCHART:

PYTHON CODE:

OOOUTPUT:

RESULT: The above programs are solved using python functions.

1
PALINDROME
EXERCISE:2

DATE: 29.11.21

AIM:

To find whether the given number is a palindrome or not using python.

ALGORITHM:

STEP 1: Enter a number num

STEP 2: A= num

STEP 3: Temp = 0, rev = 0

STEP 4: Temp = num%10

STEP 5: Rev = rev *10+ temp

STEP 6: num = num – temp

STEP 7: num = num/10

STEP 8: If num = 0 then go to step 9 else go to step

4 till num = 0

STEP 9: If rev = a then display the number is a palindrome

else display the number is not a palindrome .

FLOWCHART:

2
PYTHON CODE:

RESULT: The above program is solved using python functions.

3
PRIME NUMBER

EXERCISE:3

DATE: 29.11 21

AIM:

To find the given number is a prime number or not by using python.

ALGORITHM:

STEP 1: Input a number a

STEP 2: Assign b=1 c=0

STEP 3: If b>=a, c=1 else a%b = 0

the loop continues until c = 1

STEP 4: If c =1 display yes else display no

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:

To find the younger between the two persons using python.

ALGORITHM:

STEP 1: Start

STEP 2: Enter the age a

STEP 3: Enter the age b

STEP 4: If a>b, print b is younger else print

a is younger.

STEP 5: Stop.

FLOWCHART:

PYTHON CODE:

RESULT: The above program is solved using python functions

5
AVERAGE AGE OF 10 PLAYERS

EXERCISE:5

DATE: 29.11.21

AIM:

To find the average age of 10 players using python.

ALGORITHM:

STEP 1: Enter n = 10

STEP 2: Enter p = 1

STEP 3: Sum = 0

STEP 4: Enter the age

STEP 5: Sum = age+Sum

STEP 6: P = 1+P

STEP 7: If n<=p go to step 8, else go to step 4

STEP 8: Average = sum/n

STEP 9: “The average of 10 players is =” +average.

STEP 10: Stop.

FLOWCHART:

PYTHON CODE:

RESULT: The above program is solved using python functions

6
FACTORIAL

EXERCISE:6

DATE: 29.11.21

AIM:

To find the factorial of the given number using python.

ALGORITHM:

STEP 1: Enter a number

STEP 2: Initialize i=1, fact = 1

STEP 3: If i>n print “factorial is:” else go to step 5

7
STEP 4: Fact = fact*i, i=i+1

step 4 continues until i>n

STEP 5: Stop.

FLOWCHART:

PYTHON CODE:

RESULT: The above program is solved using python functions

FIBONACCI SERIES

EXERCISE:7

DATE: 29.11.21

AIM:

To find the fibonacci series using python.

ALGORITHM:

STEP 1: Assign i=8

STEP 2: Assign a=0, b=0, c=1

STEP 3: Display b display c

8
STEP 4: Assign i=0

if yes display the fibonacci numbers else go to step 5

STEP 5: a=b+c display a

STEP 6: b=c c=a

STEP 7: I=I-1

STEP 8: Stop

FLOWCHART:

PYTHON CODE:

RESULT: The above program is solved using python functions

9
SUM OF SQUARES OF FIRST N NATURAL NUMBERS

EXERCISE:8

DATE: 29.11.21

AIM:

To find the sum of squares of first n natural numbers using python.

ALGORITHM:

STEP 1: Start

STEP 2: Sum =0, i=1

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

STEP 7: Display sum of the first n natural numbers is, sum

FLOWCHART:

PYTHON CODE:

RESULT: The above program is solved using python functions

11
ELECTRICITY BILL GENERATOR

EXERCISE:9

DATE: 4.12.21

AIM:

To calculate the electricity bill by the given number in python

ALGORITHM:

STEP 1: Start

STEP2: Enter the number of units consumed: , get a

STEP 3: If a<50

then amount = a*2.60, surcharge = 25

else

go to step 4

STEP 4: If a<=100

amount = 130+((a-50) *3.25), surcharge = 35

else

go to step 5

STEP 5: If a<2000

amount = 130+165.50+((a-100) *5.26), surcharge = 45

else

amount = 130+165.50+((a-1000) *5.26, surcharge = 75

STEP 6: Total = amount+surcharge

STEP 7: The electricity bill is: +total

STEP 8: Stop.

12
FLOWCHART:

PYTHON CODE:

RESULT: The above program is solved using python functions.

ANAGRAM USING FOR LOOP

13
EXERCISE:10

DATE: 4.12.21

AIM:

To find whether the given strings are an anagram or not.

ALGORITHM:

STEP 1: Start

STEP 2: Input two strings from the user

STEP 3: Initialize count = 0

STEP 4: Using for loop, i i==j then count is increased by 1

STEP 5: Using if condition to compare the length of a string with count, if true print

the strings are anagrams

else

the strings aren’t anagrams

STEP 6: Stop

PYTHON CODE:

RESULT: The above program is solved using python functions

14
LENGTH OF THE NUMBER USING LOOP

EXERCISE:11

DATE: 4.12.21

AIM:

To find the length of the given number using python

ALGORITHM:

STEP 1: Take the value of the integer and store in a variable.

STEP 2: Using a while loop, get each digit of the number and increment the count

each time a digit is obtained.

STEP 3: Print the number of digits in the given integer.

STEP 4: Stop.

FLOWCHART:

PYTHON CODE:

RESULT: The above program is solved using python functions.

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 3: on the basics of percentage find grade of the student.

Step 4: check if(percentage>=90)then,print”grade a”

Step 5: if percentage is not more than 90, then check remaining conditions mentioned and print grade

PYTHON CODE:

RESULT: The above program is solved using python function

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 number for which the multiplication table is to be generated.

• Input the end value until which the table has to be generated.

• Repeat from i = 1 to end

• Display the table values in the given output format.(num * i = num*i)

PYTHON CODE:

RESULT: The above program is solved using python functions.

17
SWAPPING TWO NUMBERS

EXERCISE:14

DATE:7.12.21

AIM:

AIM:

Write a program to to swap two numbers.

ALGORITHM:

STEP 1 : “ENTER A NUMBER 1 “

STEP 2: ENTER A NUMBER 2 “

STEP 3: temp = n1

STEP 4: n1=n2

STEP 5 : n2=temp

STEP 6: PRINT(“THE VALUE OF n1 AFTER SWAPPING IS :”n1)

PRINT(“THE VALUES OF n2 AFTER SWAPPING IS :”n2)

PYTHON CODE:

RESULT: The above program is solved using python functions.

18
TRANSPOSE OF A MATRIX

EXERCISE:15

DATE: 11.12.21

AIM:

Write an algorithm and flowchart to find the transpose of a matrix.

ALGORITHM:

Step 1: start

Step 2: input a matrix “x”

Step 3: the first row will be selected as x (0)

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:

RESULT: The above program is solved using python functions.

19
DIAGONAL ELEMENTS IN A MATRIX

EXERCISE:16

DATE: 11.12.21

AIM:

To print the diagonal elements of the given matrix using python

ALGORITHM:

STEP 1: Start

STEP 2: Principal diagonal elements are found by running a

for loop until n, where n is the number of columns, and print

array[i][i], where i is the index value.

STEP 3: A loop is created to check the principal diagonal elements

STEP 4: Stop

PYTHON CODE:

RESULT: The above programs are done using python programs.

20
LENGTH OF THE GIVEN STRING

EXERCISE:17

DATE: 21.12.21

AIM:

To find the length of the string using python

ALGORITHM:

STEP 1: Initial value, tot = 0

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 3: That is, tot+1 or 0+1 or 1 gets initialized to tot.so tot = 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

total number of characters available in the given string.

that equals the length of string.

STEP 7: So print the value of tot on output, as length of string.

PYTHON CODE:

RESULT: The above programs are solved using python functions

21
FINDING THE VOWELS
EXERCISE:18

DATE: 21.12.21

AIM:

To find the vowels in the given string using python

ALGORITHM:

STEP 1: Python for loop to iterate each character in a string.

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:

RESULT: The above programs are solved using python functions

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

and take a string while declaring the variables.

STEP 2: Then, check the presence of special characters and pass it into the

function.the search function matches all the characters of the string

to the set of special characters.

STEP 3: If there is a match then it returns the matched character otherwise

it will return none.

PYTHON CODE:

RESULT: The above program is solved using python pfunctions

23
TO SPLIT AND JOIN THE STRING

EXERCISE:20

DATE: 21.12.21

AIM:

To split and join the strings using python program

ALGORITHM:

STEP 1: Start

STEP 2: Enter a string 1

STEP 3: Using split () function to split the words

STEP 4: Print the splited word

STEP 5: Enter a string 1

STEP 6: Enter a string 2

STEP 7: Using format () function to join the two strings

STEP 8: Display the strings

STEP 9: Stop.

PYTHON CODE:

RESULT: The above program is solved using python functions

24
COUNT ALL DIGITS, LETTERS AND SPECIAL CHARACTERS
EXERCISE:21

DATE: 27.12.21

AIM:

To count the characters, digits and symbols in a string using python.

ALGORITHM:

First we should use for loop to iterate characters in a string

Inside the for loop we are using elif statement

 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:

RESULT: The above program is solved using python functions.

25
REPLACE EACH SPECIAL CHARACTER WITH # SYMBOL
EXERCISE:22

DATE: 27.12.21

AIM:

To replace each and every special character by a hash (#) symbol.

ALGORITHM:

STEP 1: start

STEP 2: Use the string.punctuation constant to get the list of all punctuations.

STEP 3: Iterate each symbol from a punctuations

STEP 4: Use string function replace () to replace the current symbol in a string with #

STEP 4: Stop

PYTHON CODE:

RESULT: The above program is solved using python functions

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

STEP 7: Print result variable to display new string .

PYTHON CODE:

RESULT: The above program is solved using python functions

27
LENGTH OF THE LIST

EXERCISE:24

DATE:

AIM:

To find the length of the given list using python

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 4: Print the length of the list using print statement

STEP 5: Stop

PYTHON CODE:

RESULT: The above program is solved by using python functions

28
TO CONCATENATE TWO LISTS
EXERCISE:25

DATE: 3.1.22

AIM:

To concatenate two list given by the user using python.

ALGORITHM:

STEP 1: Start

STEP 2: Input the lists entered by the user and store it in list1 and list2.

STEP 3: Use the concatenation operator to concatenate the two lists

STEP 4: Print the concatenated list using print statement.

STEP 5: Stop.

PYTHON CODE:

RESULT: The above program is solved using python functions.

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

STEP 2: Get the list from the user.

STEP 3: Read the number in the list entered by the user.

STEP 4: Check if number%2==0 from the values in the list.

STEP 5: Then assign a variable to store the even numbers.

STEP 6: Print the even numbers from the assigned variable.

PYTHON CODE:

RESULT: The above program is solved using python programs.

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

and the count of n is been added.

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:

RESULT: The above program is solved using python functions

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:

RESULT: The above program is solved using python functions

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 1: Get the list from the user

STEP 2: Find the length of the given list using Len () function.

STEP 3: Temporarily store the first element of the list.

STEP 4: Equate the first element of the list with the last element of the list.

STEP 5: Then temporarily store the last element of the list.

STEP 6: Print the list after swapping the elements.

PYTHON CODE:

RESULT: The above program is solved using python functions

33
TO FIND THE LENGTH OF THE DICTIONARY

EXERCISE:30

DATE: 25.1.22

AIM:

Write a Python program to find the length of a dictionary.

ALGORITHM:

 Start the process.


 A dictionary is specified by the user.
 To check the length of a python dictionary, we can easily use python’s built-in function Len ().
 The Len of the dictionary is printed.
PYTHON CODE:

RESULT: The above program is solved using python functions.

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:

RESULT: The above program is solved using python functions.

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:

RESULT: The above program is solved using python functions.

36
SUM OF THE LIST
EXERCISE:33
DATE: 14.2.22
AIM:

To sum the list given using python functions

ALGORITHM:

STEP 1: Define the function to calculate the sum

STEP 2: Declare a variable for storing sum.

STEP 3: Run a loop to access each element

STEP 4: Add the element to sum

STEP 5: Return sum and initialize list

STEP 6: Call function and calculate sum

STEP 7: Print value returned by function

PYTHON CODE:

RESULT: The above program is solved using python functions

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 2: Next, I’ve defined the function as geometric_sum(n)

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:

RESULT: The above program is solved using python functions

38
PERMUTATIONS OF GIVEN STRING

EXERCISE:35

DATE: 21.2.22

AIM:

To print the permutations for a given string using python functions.

ALGORITHM:

STEP 1: Take string as the input from the user and store it in a variable str to permute the given
string

STEP 2: Declare a python function to find the permutation

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 7: Assign a new variable and store this condition prev_list[i][0:j]+str[0]+prev_list[i][j:len(str)-1]

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:

RESULT: The above program is solved using python functions

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 2: From math module import the power function

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:

RESULT: The above program is solved using python functions

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 2: Declare a python function to find the permutation

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 7: Assign a new variable and store this condition prev_list[i][0:j]+str[0]+prev_list[i][j:len(str)-1]

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:

RESULT: The above program is solved using python functions

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:

RESULT: The above program is solved using python functions

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:

RESULT: The above program is solved using python functions

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:

RESULT: The above program is solved using python functions

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:

Get the array for which the maximum is to be found

•Recursively find the maximum according to the following:

•Recursively traverse the array from the end

•Base case: If the remaining array is of length 1, return the only present element i.e., arr[0]

if(n == 1) return 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:

RESULT: The above program is solved using python functions

45
OCCURENCES OF EACH WORD

EXERCISE:42

DATE:22.2.22

AIM:

To find the occurences of each word in a text file .

ALGORITHM:

STEP 1: Input filename with location of the file.

STEP 2: Assign a variable name to read the file.

STEP 3: split the read file and store it in a variable.

STEP 4: Assign a variable and create a empty list for it.

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 7: Using for loop every element in the list is traversed.

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:

RESULT: The above program is solved using python functions

46
TOTAL NUMBER OF VOWELS

EXERCISE:43

DATE:22.2.22

AIM:

To find the total number of vowels present in a text file.

ALGORITHM:

Take the input file name from the user with the location of the file .

STEP 1: Open the file using open() function.

STEP 2: Assign the initial value of total as 0.

STEP 3: Mention all the vowels both in lowercase and uppercase.

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:

RESULT: The above program is solved using python functions

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.

STEP 5: The copied text from file is printed.

PYTHON CODE:

RESULT: The above program is solved using python functions

48
FIND THE COMMON WORDS IN A FILE

EXERCISE:45

DATE:22.2.22

AIM:

To find the most common words in a file.

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 3: Create an empty dictionary d.

STEP 4:Store each word of the text file in b using a.split().

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.

STEP 7: Close the file using close() function

PYTHON CODE:

RESULT: The above program is solved using python functions

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 1: Initialize the no of lines, no of words and no of characters to 0.

STEP 2: Using for loop every line in the file is traversed.

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:

RESULT: The above program is solved using python functions

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

You might also like