Q2.Program to generate random number and find sqaure of that number.def odd(n): if(n%2==0): print(n*n) else: print("number is odd") n=int(input("enter a number")) odd(n) >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter a number10 100
Q3.Program to generate n random number and find sqaure.import random def odd(n): if(n%2==0): print(n*n) else: print("number is odd") n=random.randint(0,100) odd(n) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== 36 >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== number is odd
Q4.Program to generate random and store in list.import random n=int(input("enter a number of random number of generate")) for i in range(0,n): x=random.randint(0,10) print(x*x) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter a number of random number of generate4 9 4 64 16
Q5.Program to genearte n random number and store sorted elemnt in list.import random l=[] n=int(input("enter a number of random number of generate")) for i in range(0,n): x=random.randint(0,10) l.append(x) print(l) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter a number of random number of generate5 [3, 2, 2, 9, 1]
import random l=[] n=int(input("enter a number of random number of generate")) for i in range(0,n): x=random.randint(0,10) l.append(x) l.sort() print(l) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter a number of random number of generate5 [0, 2, 8, 8, 9]
0 Comments