0% found this document useful (0 votes)
2 views13 pages

Python Questions

The document contains a series of Python programming exercises that cover basic mathematical operations, area calculations for various shapes, number manipulation, and control flow statements. It includes functions for swapping numbers, checking for prime numbers, generating Fibonacci series, and determining leap years, among others. Each exercise is presented with code snippets and prompts for user input.
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)
2 views13 pages

Python Questions

The document contains a series of Python programming exercises that cover basic mathematical operations, area calculations for various shapes, number manipulation, and control flow statements. It includes functions for swapping numbers, checking for prime numbers, generating Fibonacci series, and determining leap years, among others. Each exercise is presented with code snippets and prompts for user input.
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

Python Questions

[Link] two number

[Link] of triangle

i. Two Sides

base = int(input("Enter Base:"))

height = int(input("Enter Height:"))

area = (base * height)//2

print("Area=",area)

ii. Three Sides

import math

a = int(input("Enter First Side:"))

b = int(input("Enter Second Side:"))

c = int(input("Enter Third Side:"))

s = (a+b+c)//2

area = [Link](s*(s-a)*(s-b)*(s-c))

print("Area =",area)

[Link] of Circle

r = float(input("Enter Radius:"))

pi = 3.14

area = pi * r**2

print("Area Of Circle Is",area)

[Link] of rectangle

l = float(input("Enter Length:"))
w = float(input("Enter Width:"))

area = l * w

print("Area Of Rectangle =",area)

5.C to F / F to C

i. C TO F

c = float(input("Enter Celcius Degree:"))

f = c * (9/5) + 32

print("Farhehite Is:",f)

ii. F TO C

f = float(input("Enter Farhenhite Degree:"))

c = (f - 32)*(5/9)

print("Celcius Is:",c)

6. Swap two number using third variable

first_variable = int(input("Enter First Number:"))

second_variable = int(input("Enter Second Number:"))

print("...Before Swapping...")

print("First = ",first_variable)

print("Second = ",second_variable)

“””

c=a

a=b

b=c

“””

third_variable = first_variable

first_variable = second_variable
second_variable = third_variable

print("...After Swapping...")

print("First = ",first_variable)

print("Second = ",second_variable)

[Link] two number using without third variable

first_variable = int(input("Enter First Number:"))

second_variable = int(input("Enter Second Number:"))

print("...Before Swapping...")

print("First = ",first_variable)

print("Second = ",second_variable)

"""

a=a+b

b=a-b

a=a-b

"""

first_variable += second_variable

second_variable = first_variable - second_variable

first_variable =first_variable - second_variable

print("...After Swapping...")

print("First = ",first_variable)

print("Second = ",second_variable)

[Link] number among three numbers


a = int(input("Enter First Number"))

b = int(input("Enter Second Number"))

c = int(input("Enter Third Number"))

if(a>b and a>c):

big = a

elif(b>a and b>c):

big = b

else:

big = c

print("Biger Number Is:",big)

[Link] or Even number

number = int(input("Enter Number:"))

if(number % 2)== 0:

print(number,"Is Even")

else:

print(number,"Is Odd")

[Link] character is uppercase ,lowercase ,digit or special symbol

a = input("Enter Number:")

if a>='A' and a<='Z':

print("Upper Case Alphaber")

elif a>='a' and a<='z':

print("Lower Case Alphabet")

elif a>='0' and a<= '9':


print("Digit")

else:

print("Special Symbol")

11. Check the number is negative or positive

num =int(input("Enter Number:"))

if num > 0:

print("positive Number")

elif num == 0:

print(""""Integer",Neither Positive or Negative""")

else:

print("Negative Number:")

12. factorial number

num =int(input("Enter Number:"))

fact = 1

for i in range(1,num+1):

fact *= i

print(num,"Factorial Is:",fact)

[Link] Series

a=0

b=1

print("Fibonaci Series:-")

print(a)
print(b)

for i in range(1,10):

c=a+b

print(c)

a=b

b=c

[Link] series

i. up to range mean (koto bar print korbe)

times = int(input("Enter Range:"))

a=0

b=1

print("Fibonacci Series:-")

print(a)

print(b)

for i in range(1,times):

c=a+b

print(c)

a=b

b=c

ii. up to range mean (koto number porjonto print korbe)

times = int(input("Enter Range:"))

a=0

b=1

print("Fibonacci Series:-")
print(a)

print(b)

for i in range(1,times):

c=a+b

if c > times:

break

print(c)

a=b

b=c

[Link] prime number

num = int(input("Enter Number:"))

count = 0

if num > 1:

for i in range(1,num+1):

if(num%i)==0:

count += 1

if count == 2:

print(num,"Is Prime Number")

else:

print(num,"Is Not Prime")

else:

print(num,"Is Not Prime")

[Link] number

n = int(input("Enter Number:"))
copy = n

count = 0

arm = 0

while n!=0:

count += 1

n //= 10

n = copy

for i in range(1,count+1):

r = n % 10

arm += r**count

n //= 10

if arm == copy:

print("Armstrong Number")

else:

print("Not Armstrong Number")

[Link] of two number

f1 = int(input("Enter Number:"))

f2 = int(input("Enter Number:"))

if f1 > f2:

lcm = f1

else:

lcm = f2

while 1:

if(lcm % f1)==0 and (lcm % f2)==0:


print("LCM is=",lcm)

break

lcm += 1

[Link]/HCF of two number

f1 = int(input("Enter Number:"))

f2 = int(input("Enter Number:"))

for i in range(1,f1+f2):

if(i<=f1 and i<=f2):

if(f1%i)==0 and (f2%i)==0:

gcd = i

print("GCD =",gcd)

[Link] Natural numbers upto n

n = int(input("Enter n Value:"))

for i in range(1,n+1):

print(i,end = " ")

[Link] of digits

n = int(input("Enter The Number:"))

ans = 0

while n!=0:

r = n % 10

ans += r

n //= 10
print("Sum Of Digits:",ans)

[Link] table

n = int(input("Enter Number To Print MultiPlication Table"))

for i in range(1,10+1):

print(n," X ",i," = ",n*i)

[Link] number up to range

start = int(input("Enter Number:"))

end = int(input("Enter Number:"))

for i in range(start,end+1):

count = 0

for j in range(1,i+1):

if(i%j)==0:

count += 1

if(count == 2):

print(j)

[Link] prime number Upto Range

start = int(input("Enter Number:"))

end = int(input("Enter Number:"))

for i in range(start,end+1):

count = 0

for j in range(1,i+1):

if(i%j)==0:
count += 1

if(count == 2 and (j%2)!=0 ):

print(j)

[Link] year or not

year = int(input("Enter year:"))

if(((year%4)==0 and (year%100)!=0)or (year%400)==0):

print(year,"Is Leap Year")

else:

print(year,"Is Not A Leap Year")

[Link] Fibonacci Upto Range

n = int(input("Enter Range:"))

a=0

b=1

print("Fibonacci Series")

for i in range(1,n+1):

c = a+b

count = 0

for j in range(1,c+1):

if(c%j)==0:

count += 1

if count == 2:

print(c)

a=b
b=c

[Link] Palindrom or not

n = input("Enter Number:")

copy = n

aa = n[::-1]

if copy == aa:

print("Palindrom")

You might also like