Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (23)

Q1.Program to swap two number.

def swap(a,b): temp=a a=b b=temp print("after swap a is",a) print("after swap b is",b) a=int(input("enter number a")) b=int(input("enter number b")) swap(a,b) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== enter number a2 enter number b3 after swap a is 3 after swap b is 2



Q2.Program to find solution of quadratic equation.

import cmath a=float(input("enter a")) b=float(input("enter b")) c=float(input("enter c")) d=(b**2)-(4*a*c) sol1=(-b-cmath.sqrt(d))/(2*a) sol2=(-b+cmath.sqrt(d))/(2*a) print(sol1,sol2) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== enter a8 enter b5 enter c9 (-0.3125-1.0135796712641785j) (-0.3125+1.0135796712641785j)



Q3.Program to find number is harshad or not.

n=int(input("enter a number")) num=n s=0 r=0 while(n>0): r=n%10 s=s+r n=n//10 if (num%s==0): print(str(num)+ "is harshad number") else: print(str(num)+" is not harshad number") Output >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== enter a number156 156is harshad number >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== enter a number123 123 is not harshad number


Q4.Program to display calendar.

import calendar yy=int(input("enter year")) mm=int(input("enter month")) print(calendar.month(yy,mm)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== enter year2023 enter month9 September 2023 Mo Tu We Th Fr Sa Su 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 26 27 28 29 30


Q5.Program to find ascii value of entered value.

c=input("enter value") print("ascii value of entered value is ",ord(c)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/aa.py ==================== enter valuea ascii value of entered value is 97 >>>



Post a Comment

0 Comments