Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1. Write a python program that accepts a number and prints the sum of its factors.

2. Write a python program that finds the average, maximum, minimum, and sum of n
numbers input by the user.
3. Write a python program that generates a random number in the range 0 to 100 and
prompts the user to guess and enter the number continuously until the user’s input
matches the randomly generated number. The program should inform the user if
his/her guess is less/more than the random number. if the user can't guess the value
by entering at most 7 guesses the program should print GAME OVER

4. Write a function that calculates the gcd of two numbers that are given as parameters

5. The Collatz conjecture


Let’s look at a simple sequence that has fascinated mathematicians for many years. They
still cannot answer even quite simple questions about this.

The “computational rule” for creating the sequence is to start from some given n, and to
generate the next term of the sequence from n, either by halving n, (whenever n is
even), or else by multiplying it by three and adding 1. The sequence terminates when n
reaches 1.
6. Write a function that counts the frequency of a given digit in a number.
frequency_of_num(15213323231790, 3) will print 4.
7. Write a function that calculates and returns the distance between two points in the
Cartesian coordinate system
P1 = x1, y1
P2 = x2,y2

8. A palindrome is a word that reads identically backward and forward, such as ‘level’ or
‘noon’. Write a predicate function with an iterative algorithm IsPalindrome(string) that
returns true if the string is a palindrome. In addition, design and write a test program
that calls IsPalindrome to demonstrate that it works.
9. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is
equal to the number itself. For example, 371 is an Armstrong number
Since 33 + 73 + 13 = 371.
Write a program to find all Armstrong number in the range of 0 and 999
10. Write a program that finds an integer between 1 and 10000 that has the largest number of
divisors, and how many divisors does it have?
11. Write function exclamation() that takes as input a string and returns it with this modification:
Every vowel is replaced by four consecutive copies of itself and an exclamation mark (!) is added
at the end.
>>> exclamation('argh')
'aaaargh!'
>>> exclamation('hello')
'heeeelloooo!'
12. Build a function that records the number of words in a given list and returns the counter
dictionary

>>> count_words(['the', 'clown', 'ran', 'after', 'the', 'car', 'and', 'the', 'car', 'ran', 'into',
'the', 'tent', 'and', 'the', 'tent', 'fell', 'down', 'on', 'the', 'clown', 'and', 'the', 'car'])

Return Value: {'and': 3, 'on': 1, 'ran': 2, 'car': 3, 'into': 1, 'after': 1, 'clown': 2, 'down': 1,
'fell': 1, 'the': 7, 'tent': 2}

You might also like