Ticker

6/recent/ticker-posts

Python subjective question for competitive exam (34)

Q1Program to shuffle and print the list [3,6,7,8].

from random import shuffle li=[3,6,7,8] shuffle(li) print(li) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== [6, 7, 8, 3]

Q2 Program to generate sentence where subject is in ["ram","sham"] and verb is ["play","learn"] and object is["hockey",football"].

subject=["ram","sham"] verb=["play","learn"] object=["hockey","football"] for i in range(len(subject)): for j in range(len(verb)): for k in range(len(object)): sentence="%s %s %s" %(subject[i],verb[i],object[k]) print(sentence) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== ram play hockey ram play football ram play hockey ram play football sham learn hockey sham learn football sham learn hockey sham learn football



Q3.Program to print list after removing all duplicate valuue from list.

def removeduplicate(li): newlist=[] for item in li: if item not in newlist: newlist.append(item) return(newlist) li=[1,1,2,3,4,3,4,5,5,4,3,2] print(removeduplicate(li)) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== [1, 2, 3, 4, 5]

Q4.Program to find permutaion of string.

result=[] def permu(data,i,n): if i==n: result.append("".join(data)) for j in range(i,n+1): data[i],data[j]=data[j],data[i] permu(data,i+1,n) data[i],data[j]=data[j],data[i] permu(list('abc'),0,2) print(result) Output >>> ==================== RESTART: C:\Users\Dell\Desktop\ss.py ==================== ['abc', 'acb', 'bac', 'bca', 'cba', 'cab']

Q5.Program to find permutaion of string and sort list in reverse order.

result=[] def permu(data,i,n): if i==n: result.append("".join(data)) for j in range(i,n+1): data[i],data[j]=data[j],data[i] permu(data,i+1,n) data[i],data[j]=data[j],data[i] permu(list('abc'),0,2) d=sorted(result,reverse=True) print(d) Output >>> ==================== RESTART: C:\Users\Dell\Desktop\ss.py ==================== ['cba', 'cab', 'bca', 'bac', 'acb', 'abc']





Python subjective question for competitive exam (33)
Python subjective question for competitive exam (32)
Python subjective question 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