Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (33)

Q1Program which will find all such numbers which are divisible by 7 but are not a multiple of 5, and between 2000 and 2100.

l=[] for i in range(2000,2100): if(i%7==0)and(i%5!=0): l.append(str(i)) print(l) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== ['2002', '2009', '2016', '2023', '2037', '2044', '2051', '2058', '2072', '2079', '2086', '2093']

Q2 With a given number n program to generate dictionary that contains(i,i*i) such that number between 1 and n.

n=int(input("enter number")) d=dict() for i in range(1,n+1): d[i]=i*i print(d) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter number5 {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}



Q3.Program that accept a sentence and calculate the number of letter and digit.

i=input("enter string") letter=0 digit=0 for c in i: if c.isdigit(): digit+=1 elif c.isalpha(): letter+=1 else: pass print(digit) print(letter) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter stringaba123 3 3

Q4.Program that accept a sentence and calculate number of uppercase and lowercase letters.

s=input("enter sentence"); ucase=0 lcase=0 for c in s: if c.isupper(): ucase+=1 elif c.islower(): lcase+=1 else: pass print('uppercase',ucase) print('lowercase',lcase) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter sentenceAbC uppercase 2 lowercase 1

Q5.Program to find factorial and store result in dictionary.

def fact(x): if x==0: return 1 else: return(x*fact(x-1)) x=int(input("enter number")) d=dict() d[x]=fact(x) print(d) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter number5 {5: 120}





Python subjective question for competitive exam (32)
Python subjective question(recursion) for competitive exam (31)
Python subjective question for competitive exam (30)
Python subjective question for competitive exam (29)
Python subjective question for competitive exam (28)
Python subjective question for competitive exam (27)
Python subjective question for competitive exam (26)
Python subjective question for competitive exam (25)
Python subjective question for competitive exam (24)
Python subjective question for competitive exam (23)
Python subjective question for competitive exam (22)
Python subjective question for competitive exam (21)
Python subjective question for competitive exam (20)
Python subjective question for competitive exam (19)
Python subjective question for competitive exam (18)
Python subjective question for competitive exam (17)
Python subjective question for competitive exam (16)
Python subjective question for competitive exam (15)
Python subjective question for competitive exam (14)
Python subjective question for competitive exam (13)
Python subjective question for competitive exam (12)
Python subjective question for competitive exam (11)
Python subjective question for competitive exam (10)
Python subjective question for competitive exam (9)
Python subjective question for competitive exam (8)
Python subjective question for competitive exam (7)
Python subjective question for competitive exam (6)
Python subjective question for competitive exam (5)
Python subjective question for competitive exam (4)
Python subjective question for competitive exam (3)
Python subjective question for competitive exam (2)
Python subjective question for competitive exam (1)

Post a Comment

0 Comments