[go: up one dir, main page]

0% found this document useful (0 votes)
11 views2 pages

House of Algorithms-Qns

The document outlines ten Python programming tasks, including calculating the difference between squared sums, identifying abundant numbers, generating lucky numbers, implementing the Sieve of Eratosthenes for prime numbers, finding quadratic roots, parsing math formulas, computing GCD and LCM using the Euclidean algorithm, identifying perfect squares, checking for Disarium numbers, and determining if three points are collinear. Each task includes a brief description and expected outputs for specific inputs. The document serves as a guide for practicing various programming concepts in Python.

Uploaded by

x4ms7724r7
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)
11 views2 pages

House of Algorithms-Qns

The document outlines ten Python programming tasks, including calculating the difference between squared sums, identifying abundant numbers, generating lucky numbers, implementing the Sieve of Eratosthenes for prime numbers, finding quadratic roots, parsing math formulas, computing GCD and LCM using the Euclidean algorithm, identifying perfect squares, checking for Disarium numbers, and determining if three points are collinear. Each task includes a brief description and expected outputs for specific inputs. The document serves as a guide for practicing various programming concepts in Python.

Uploaded by

x4ms7724r7
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

HOUSE OF ALGORITHMS

1. Write a Python program to calculate the difference between the squared sum of the first
n natural numbers and the sum of squared first n natural numbers.(default value of
number=2).
if n=5 then the expected out is 170

2. Askjdxas
Write a Python program to find out if the given number is abundant.
Note: In number theory, an abundant number or excessive number is a number for
which the sum of its proper divisors is greater than the number itself. The integer 12 is
the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16.
Test Data:
If is_abundant(12)
If is_abundant(13)
Expected Output:
True
False
3. Write a Python program to print the first n lucky numbers.
Lucky numbers are defined via a sieve as follows.
Begin with a list of integers starting with 1 :
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, .
...
Now eliminate every second number :
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ...
The second remaining number is 3, so remove every 3rd number:
1, 3, 7, 9, 13, 15, 19, 21, 25, ...
The next remaining number is 7, so remove every 7th number:
1, 3, 7, 9, 13, 15, 21, 25, ...
Next, remove every 9th number and so on.
Finally, the resulting sequence is the lucky numbers.

Input a Number: 10
[1, 3, 7, 9, 13, 15, 21, 25, 31, 33]
4. Sieve of Eratosthenes : Write a Python program to print all primes
(Sieve_of_Eratosthenes) smaller than or equal to a specified number.
In mathematics, the sieve of Eratosthenes, one of a number of prime number sieves, is a
simple, ancient algorithm for finding all prime numbers up to any given limit. It does so
by iteratively marking as composite (i.e., not prime) the multiples of each prime, starting
with the multiples of 2.
if n=100
Then the expected output
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83,
89, 97]
5. Quadratic Roots Finder : Write a Python program to find the roots of a quadratic function.
Expected Output :
Quadratic function : (a * x^2) + b*x + c
a: 25
b: 64
c: 36
There are 2 roots: -0.834579 and -1.725421
6. Math Formula Parser : Write a Python program to parse math formulas and put
parentheses around multiplication and division.
Sample data : 4+5*7/2
Expected Output :
4+((5*7)/2)
7. Euclidean Algorithm for GCD : Write a Python program to implement the Euclidean
Algorithm to compute the greatest common divisor (GCD) and LCM
Expected Output :
if input is 15,3,9
GCD is 3 LCM=135
8. Perfect Squares Finder : Write a Python program to find perfect squares between two
given numbers.
if input is (1,30)
Then output is [1, 4, 9, 16, 25]
9. Disarium Number Checker : Write a Python program to check whether a given number
is a Disarium number or an unhappy number.
A Disarium number is a number defined by the following process:
Sum of its digits powered with their respective position is equal to the original number.
For example 175 is a Disarium number
For example : 25 is Unhappy number
10. Program to check if three points are collinear
Input : (1, 1), (1, 4), (1, 5)
Output : Yes , The points lie on a straight line

Input : (1, 5), (2, 5), (4, 6)


Output : No , The points do not lie on a straight line

You might also like