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

Exercise

The document provides instructions for 10 Python exercises to practice fundamental programming concepts like finding the sum of digits in a number, checking if a number is an Armstrong number, checking if a string is a palindrome, printing frequencies of elements in an array, finding prime factors of a number, calculating binomial coefficients, searching arrays using linear and binary search, finding frequent words in a text file, printing lengths of country names in a tuple, and sorting a list of names in alphabetical order. The exercises are meant to be done without using Python libraries for best learning and revision of basic programming skills.

Uploaded by

pinof73420
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Exercise

The document provides instructions for 10 Python exercises to practice fundamental programming concepts like finding the sum of digits in a number, checking if a number is an Armstrong number, checking if a string is a palindrome, printing frequencies of elements in an array, finding prime factors of a number, calculating binomial coefficients, searching arrays using linear and binary search, finding frequent words in a text file, printing lengths of country names in a tuple, and sorting a list of names in alphabetical order. The exercises are meant to be done without using Python libraries for best learning and revision of basic programming skills.

Uploaded by

pinof73420
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DSECLPFDS/AIMLCPFDS

Python Exercises for Practice (Topics S1 and S2)

Instructions: Do not use any Python libraries and write the


following codes from scratch for best learning/ revision.

1. Given a number, find the sum of its digits. Take the number as
an input from the user.
2. Given a number, check whether the given number is an
Armstrong number or not. A positive integer is called an
Armstrong number of order n if:
abcd... = an + bn + cn + dn + ...
Example: 153 = 1*1*1 + 5*5*5 + 3*3*3
153 is an Armstrong number of order 3.
Inputs from the user will be number and order n.
3. Given a string, write a python function to check if it is
palindrome or not. A string is said to be palindrome if the reverse
of the string is the same as string. For example, “malayalam” is a
palindrome, but “music” is not a palindrome.
4. Given an array which may contain duplicates, print all elements
and their frequencies.
5. Given a number n, write a function to print all prime factors of
n. For example, if the input number is 12, then output should be
“2 2 3”.
6. Given two numbers n and r, find the value of nCr (binomial
coefficient: nCr = (n!) / (r! * (n-r)!))
7. Searching: Given a sorted array arr[] of n elements, write a
function to search a given element x in arr[]. Do it using linear
and binary search techniques.
8. Input a text file (containing 1 or more paragraphs of English
text) from the user, parse this file to display the frequency of
occurrence of each word in this text file. Find the 3 most frequent
words as well.
9. Define a tuple with the names of three countries. Write a
program that prints each country's name along with its length.
10. Create a program that prompts the user to enter a list of names.
Then, display the list in alphabetical order.

*****

You might also like