[go: up one dir, main page]

0% found this document useful (0 votes)
61 views4 pages

Arithmetic Operators 45 Solutions

The document contains a series of Python practice questions focused on arithmetic operators and various mathematical operations. Each question includes code snippets that prompt user input and perform calculations such as addition, subtraction, multiplication, division, and more complex operations like calculating areas, averages, and solving equations. It serves as a comprehensive guide for practicing Python programming skills related to arithmetic and mathematical functions.

Uploaded by

sandeep
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)
61 views4 pages

Arithmetic Operators 45 Solutions

The document contains a series of Python practice questions focused on arithmetic operators and various mathematical operations. Each question includes code snippets that prompt user input and perform calculations such as addition, subtraction, multiplication, division, and more complex operations like calculating areas, averages, and solving equations. It serves as a comprehensive guide for practicing Python programming skills related to arithmetic and mathematical functions.

Uploaded by

sandeep
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/ 4

Solutions for Python Arithmetic Operators Practice Questions

1. a = int(input('Enter first number: '))


b = int(input('Enter second number: '))
print('Sum:', a + b)
2. a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
print('Difference:', a - b)
3. a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
print('Product:', a * b)
4. a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
print('Quotient:', a / b)
5. a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
print('Remainder:', a % b)
6. a = int(input('Enter a number: '))
print('Square:', a ** 2)
7. a = int(input('Enter a number: '))
print('Cube:', a ** 3)
8. a = int(input('Enter a number: '))
a += 1
print('Incremented:', a)
9. a = int(input('Enter a number: '))
a -= 1
print('Decremented:', a)
10. a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
temp = a
a=b
b = temp
print(a, b)
11. a = int(input('Enter first number: '))
b = int(input('Enter second number: '))
a=a+b
b=a-b
a=a-b
print(a, b)
12. l = float(input('Length: '))
b = float(input('Breadth: '))
print('Area:', l * b)
13. b = float(input('Base: '))
h = float(input('Height: '))
print('Area:', 0.5 * b * h)
14. a = float(input('Enter first number: '))
b = float(input('Enter second number: '))
c = float(input('Enter third number: '))
print('Average:', (a + b + c) / 3)
15. a = int(input('Enter a number: '))
print('Even' if a % 2 == 0 else 'Odd')
16. mins = int(input('Enter minutes: '))
print(f'{mins // 60} hour(s) and {mins % 60} minute(s)')
17. p = float(input('Principal: '))
r = float(input('Rate: '))
t = float(input('Time: '))
print('CI:', p * (1 + r / 100)**t - p)
18. marks = float(input('Marks obtained: '))
total = float(input('Total marks: '))
print('Percentage:', (marks / total) * 100)
19. c = float(input('Celsius: '))
print('Fahrenheit:', (c * 9/5) + 32)
20. f = float(input('Fahrenheit: '))
print('Celsius:', (f - 32) * 5/9)
21. r = float(input('Radius: '))
print('Perimeter:', 2 * 3.14159 * r)
22. l = float(input('Length: '))
b = float(input('Breadth: '))
print('Perimeter:', 2 * (l + b))
23. a, b, c = map(int, input('Enter three numbers: ').split())
print('Max:', max(a, b, c))
24. import cmath
a = float(input('a: '))
b = float(input('b: '))
c = float(input('c: '))
d = (b**2) - (4*a*c)
sol1 = (-b - cmath.sqrt(d)) / (2*a)
sol2 = (-b + cmath.sqrt(d)) / (2*a)
print(sol1, sol2)
25. year = int(input('Enter year: '))
print('Leap Year' if (year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)) else 'Not Leap Year')
26. n = int(input('Enter n: '))
print('Sum:', n * (n + 1) // 2)
27. n = int(input('Enter n: '))
print('Sum of squares:', n*(n + 1)*(2*n + 1)//6)
28. n = int(input('Enter n: '))
print('Sum of cubes:', (n*(n + 1)//2)**2)
29. n = int(input('Enter number: '))
sum = 0
while n:
sum += n % 10
n //= 10
print('Sum of digits:', sum)
30. n = int(input('Enter number: '))
rev = 0
while n:
rev = rev * 10 + n % 10
n //= 10
print('Reversed:', rev)
31. n = int(input('Enter number: '))
orig = n
rev = 0
while n:
rev = rev * 10 + n % 10
n //= 10
print('Palindrome' if rev == orig else 'Not Palindrome')
32. n = int(input('Enter number: '))
num = n
s=0
while n:
d = n % 10
s += d ** len(str(num))
n //= 10
print('Armstrong' if s == num else 'Not Armstrong')
33. n = int(input('Enter number: '))
fact = 1
for i in range(1, n + 1):
fact *= i
print('Factorial:', fact)
34. import math
a = int(input('Enter a: '))
b = int(input('Enter b: '))
print('GCD:', math.gcd(a, b))
35. def lcm(x, y): return x * y // math.gcd(x, y)
a = int(input('Enter a: '))
b = int(input('Enter b: '))
print('LCM:', lcm(a, b))
36. base = int(input('Base: '))
exp = int(input('Exponent: '))
res = 1
for _ in range(exp):
res *= base
print(res)
37. bin_num = input('Binary: ')
dec = 0
for i in range(len(bin_num)):
dec += int(bin_num[-1 - i]) * (2 ** i)
print('Decimal:', dec)
38. dec = int(input('Decimal: '))
bin_num = ''
while dec:
bin_num = str(dec % 2) + bin_num
dec //= 2
print('Binary:', bin_num)
39. n = int(input('Enter upper limit: '))
for i in range(2, n + 1):
if all(i % j != 0 for j in range(2, int(i ** 0.5) + 1)):
print(i, end=' ')
40. n = int(input('Enter n: '))
a, b = 0, 1
while a <= n:
print(a, end=' ')
a, b = b, a + b
41. a = int(input('First term: '))
r = int(input('Common ratio: '))
n = int(input('Terms: '))
print('Sum:', a * (1 - r**n) // (1 - r))
42. n = int(input('How many numbers? '))
product = 1
for _ in range(n):
product *= int(input())
print('Product:', product)
43. expr = input('Enter expression: ')
print('Result:', eval(expr))
44. a = float(input('Enter first number: '))
b = float(input('Enter second number: '))
op = input('Enter operation (+,-,*,/): ')
if op == '+': print(a + b)
elif op == '-': print(a - b)
elif op == '*': print(a * b)
elif op == '/': print(a / b)
45. a1 = int(input('a1: '))
b1 = int(input('b1: '))
c1 = int(input('c1: '))
a2 = int(input('a2: '))
b2 = int(input('b2: '))
c2 = int(input('c2: '))
d = a1*b2 - a2*b1
x = (c1*b2 - c2*b1) / d
y = (a1*c2 - a2*c1) / d
print('x =', x, ', y =', y)

You might also like