-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop.txt
97 lines (88 loc) · 3.47 KB
/
loop.txt
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Q.1- Take 10 integers from user and print it on screen.
l=[]
print("Enter 10 num")
for i in range(1,11):
a=int(input())
l.append(a)
for i in range(1,11):
print(l[i-1])
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Q.2- Write an infinite loop.An infinite loop never ends. Condition is always true.
while True:
print("hello")
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Q.3- Create a list of integer elements by user input. Make a new list which will store square of elements of previous list.
l=[]
l2=[]
print("Enter 5 num")
for i in range(0,5):
a=int(input())
l.append(a)
for i in range(0,5):
l2.append((l[i]*l[i]))
for i in range(0,5):
print(l2[i])
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Q.4- From a list containing ints, strings and floats, make three lists to store them separately
my=[50,"ABC",8.5,999999999]
print(my)
inte=[]
flo=[]
strg=[]
for i in range(0,4):
if(type(my[i])==int):
inte.append(my[i])
elif(type(my[i])==float):
flo.append(my[i])
else:
strg.append(my[i])
print(inte)
print(flo)
print(strg)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Q.5- Using range(1,101), make a list containing even and odd numbers.
odd=[]
eve=[]
for i in range(1,101):
if(i%2==0):
odd.append(i)
else:
eve.append(i)
print("odd list")
print(odd)
print("even list")
print(eve)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Q.6- Print the following patterns:
*
**
***
****
for i in range(0,5):
for j in range(0,i+1):
print("*",end="")
print("\n")
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Q.7- Create a user defined dictionary and get keys corresponding to the value using for loop.
d={}
for i in range(1,5):
key=input("enter key")
val=input("enter its val")
d[key]=val
print(d)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Q.8- Take inputs from user to make a list. Again take one input from user and search it in the list and delete that element, if found. Iterate over list using for loop.
l=[]
print("Enter 5 num")
for i in range(0,5):
a=int(input())
l.append(a)
print("enter number to search")
b=int(input("enter"))
for k in range(0,5):
if(b==l[k]):
print("element found")
break
l.pop(k)
print("new list")
print(l)