Professional Documents
Culture Documents
Python 033
Python 033
Program:
Algorithm:
1. Start
2. Input two numbers.
3. Find the smaller number.
4. Iterate from 1 to smaller number.
5. Check if both numbers are divisible
by iteration.
6. If the condition is satisfied update
the value of HCF with the current
iteration.
7. Print the calculated value of HCF.
8. Stop.
Output:
2. Write a program to find the Factorial of number ‘n’ using recursive function.
Program:
Algorithm:
1. Start.
2. Define a recursive function that computes the factorial
of a given number.
3. Obtain user input for value of ‘n’.
4. Call the defined factorial function.
5. Print the calculated Factorial of ‘n’.
6. Stop.
Output:
Program:
Algorithm:
1. Start.
2. Get a random number using
randint function.
3. Input the guess from the user.
4. If guess>number say lower
if guess<number say higher
if guess=number say Correct.
5. Repeat till user guesses the
number.
6. Stop
Output:
5. Write a Binary Search function which searches an item in a sorted list. The function should
return the index of each element to be searched in the list.
Program:
Algorithm:
1. Start.
2. Input a sorted array
and a number to be
found.
3. Set low to 0 and
high to length of list-
1.
4. Find middle element
and compare with the
number to be found.
5.If mid<num, right
if mid>num, left
6. Repeat till number is
found.
7. Print position of
number.
8. Stop.
Output:
6. Write a Bubble sort function to sort a given list. Print the original and sorted lost.
Program:
Output:
Algorithm:
1. Start.
2. Input a list to be sorted.
3. Compare each element with next number till all the conditions are satisfied.
4. This will sort the list.
5. Stop
7. Write a program to remove all punctuations from the string provided by the user.
Program:
Algorithm:
1. Start.
2. Input the string.
3. Compare each character with
function isalnum() and
eliminate all punctuations.
4. Print the modified string.
5.Stop.
Output:
8. Write a python program that accepts a sentence and calculates the number of words, digits,
uppercase letters and lowercase letters.
Program:
Algorithm:
1. Start.
2. Input sentence as input.
3. Count the numbers of
words, digits, uppercase and
lowercase letters.
4. Print the original string
with all counts.
5. Stop.
Output: