0% found this document useful (0 votes)
7 views6 pages

Math and Python Problems with Solutions

The document contains a series of mathematical and programming questions divided into beginner, intermediate, and advanced levels. Each question is followed by its answer, covering topics such as basic arithmetic, Python programming, data structures, and algorithms. The questions test problem-solving skills and understanding of programming concepts.

Uploaded by

rakshad2005
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)
7 views6 pages

Math and Python Problems with Solutions

The document contains a series of mathematical and programming questions divided into beginner, intermediate, and advanced levels. Each question is followed by its answer, covering topics such as basic arithmetic, Python programming, data structures, and algorithms. The questions test problem-solving skills and understanding of programming concepts.

Uploaded by

rakshad2005
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

Beginner Level:

1. If 3 workers complete a task in 6 days, how many days will 6 workers take (same rate)?
→ Answer: 3 days

2. Find the missing number: 2, 6, 12, 20, ?


→ Answer: 30 (Pattern: +4, +6, +8, +10)

3. Average of 6, 8, 10, 12 = ?
→ Answer: 9

4. If selling price = ₹240, profit = 20%, find cost price.


→ Answer: ₹200

5. The time in 24-hour format for 2:45 PM is?


→ Answer: 14:45

6. What is the output of:


x = [1, 2, 3]
print(x*2)
→ Answer: [1, 2, 3, 1, 2, 3]

7. Which of these is mutable?


a) tuple b) string c) list d) int
→ Answer: c) list

8. What will type({}) return?


→ Answer: <class 'dict'>

9. Which keyword is used to handle exceptions?


→ Answer: try and except

10. Output of:

print(bool(0), bool(""), bool([]))

→ Answer: False False False

11. Write code to print even numbers from 1 to 10.


for i in range(1, 11):
if i % 2 ==0:
print(i, end=” “)
→ Answer: 2 4 6 8 10
12. Predict:
x = 10
x += 5
print(x)
→ Answer: 15

13. Output:
s = "Hello"
print(s[::-1])
→ Answer: olleH

14. Find the output:


a = [10, 20, 30]
print(a[1:])
→ Answer: [20, 30]

15. What’s wrong with:


if a = 5:
print(a)
→ Answer: SyntaxError (should be == for comparison)

Intermediate Level:
1. A train travels 120 km in 3 hours. What’s its speed?
→ Answer: 40 km/hr

2. Ratio of boys to girls is 3:5. If there are 40 students, how many boys?
→ Answer: 15

3. A number doubled then increased by 5 gives 21. Find the number.


→ Answer: 8

4. Find missing: 3, 9, 27, ?, 243


→ Answer: 81

5. If simple interest on ₹2000 for 2 years is ₹400, find rate.


→ Answer: 10%
6. What’s output:
def f(x=[]):
[Link](1)
return x
print(f(), f())
→ Answer: [1] [1, 1]

7. Which data structure allows duplicates?


→ Answer: List

8. What’s the result:


a = {1, 2, 3}
b = {3, 4}
print(a & b)
→ Answer: {3}

9. What’s difference between is and ==?


→ Answer: is → identity, == → value equality

10. Output:

print("5" * 3)

→ Answer: 555

11. Write a Python function to check if a number is prime.

def is_prime(n):
if n < 2: return False
for i in range(2, int(n**0.5)+1):
if n % i == 0: return False
return True

→ Answer: Correct

12. Predict:
x = [i**2 for i in range(3)]
print(x)
→ Answer: [0, 1, 4]

13. Output:
a = [ 1, 2, 3]
print([Link](), a)

→ Answer: 3 [1, 2]
14. Reverse a string without using [::-1].
s = "abc"
rev = ""
for ch in s:
rev = ch + rev
print(rev)

→ Answer: cba

15. Lambda usage:


f = lambda x: x*2
print(f(5))

→ Answer: 10

Advanced Level:
1. If a man’s age is 4x and his son’s is x, after 5 years ratio = 3:1. Find x.
→ Answer: 5

2. Two pipes fill a tank in 12 min and 15 min. Together time = ?


→ Answer: 6 min 40 sec

3. If log₂(x) = 5, find x.
→ Answer: 32

4. Find missing term: 2, 5, 10, 17, 26, ?


→ Answer: 37 (Add successive odd numbers)

5. A boat moves upstream at 8 km/h, downstream at 12 km/h. Speed of stream?


→ Answer: 2 km/h

6. Output:
def fun(x, y, *args, **kwargs):
print(len(args) + len(kwargs))
fun(1, 2, 3, 4, a=5, b=6)
→ Answer: 4

7. Output:
x = [[0]*3]*3
x[0][0] = 1
print(x)
→ Answer: [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
8. Explain difference between deep copy and shallow copy.
→ Answer: Shallow copy copies reference; deep copy duplicates all nested objects.

9. What will this print?


a = [1, 2, 3]
b = a
[Link](4)
print(a)
→ Answer: [1, 2, 3, 4]

10. Output:

print(sum(i for i in range(5) if i%2))

→ Answer: 4

11. Write a function to find the nth Fibonacci number using recursion.
→ Answer:
def fib(n):
if n <= 1: return n
return fib(n-1) + fib(n-2)

12. What’s output:


x = {i:i**2 for i in range(3)}
print(x)
→ Answer: {0:0, 1:1, 2:4}

13. Write code to count frequency of each character in a string.


from collections import Counter
print(Counter("banana"))
→ Answer: {'b':1, 'a':3, 'n':2}

14. Output:
a = [1,2,3,4,5]
print(list(map(lambda x:x%2==0, a)))
→ Answer: [False, True, False, True, False]

15. Function to check if string is palindrome (ignore case/spaces).


def is_pal(s):
s = ''.join([Link]().split())
return s == s[::-1]
→ Answer: Correct

You might also like