-
Notifications
You must be signed in to change notification settings - Fork 1
/
VAT19.txt
278 lines (218 loc) · 5.38 KB
/
VAT19.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
011235
dict={1:'a',2:'b',3:'c'}
dict1={k*2:v for(k,v) in dict.items()}
o/p= {2: 'a', 4: 'b', 6: 'c'}
numbers=range(10)
d1={n:n**2 for n in numbers if n%2==0}
d1
{0: 0, 2: 4, 4: 16, 6: 36, 8: 64}
farenhite={t1:-30,t2:-20,t3:-10,t4:0}
celsius={k:(float(5)/9)*(v-32) for(k,v) in farenhite.items()}
celsius
{'t1': -34.44444444444444, 't2': -28.88888888888889, 't3': -23.333333333333336, 't4': -17.77777777777778}
create a dictionary from the following where the values will be
greater than 2 and divisible by both 2 and 3
d1={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':9,'i':12}
d2={k:v for(k,v) in d1.items() if v>2 if v%2==0 if v%3==0}
d2
{'f': 6, 'i': 12}
clear() remove all items
copy() return shallow copy
fromkeys() create dictionary from given sequence
get() return value of the key
items() return key value pair
keys() return keys
values() return values
popitem() returns and removes element
setdefault() inserts key with the value if key is not present
update() updates
any() checks if any element is true
convert list into dictionary
keys1=[]
values1=[]
count=5
for i in range(0,count):
e=input()
keys1.append(e)
for i in range(0,count):
e=input()
values1.append(e)
d1=dict(zip(keys1,values1))
print(d1)
#####
keys1=[]
values1=[]
c=int(input('Enter length of the dictionary\n'))
for i in range(0,c):
e=input('Enter key element\n')
keys1.append(e)
f=input('Enter value element\n')
values1.append(f)
d1=dict(zip(keys1,values1))
print(d1)
LIST MANIPULATION
name='IT'
print('Hello,%s!'%name)
Hello,IT!
name='john'
age=23
print('%s is %d years old'%(nmae,age))
john is 23 years old
mylist=[1,2,3]
>>> print('a list:%s'%mylist[0])
a list:1
st='Hello world'
>>> print("single quates are ''")
single quates are ''
>>> len(st)
11
>>> st.index('w')
6
>>> st.count('i')
0
>>> st[3:7]
'lo w'
>>> st[2:7:2]
'low'
>>> st[::-1]
'dlrow olleH'
>>> st.upper()
'HELLO WORLD'
>>> st.lower()
'hello world'
>>> st.startswith('H')
True
>>> st.endswith('s')
False
>>> st.endswith('ld')
True
count=0
while(count<5):
print(count)
count+=1
else:
print('count value reaches%d'%count)
o/p
0
1
2
3
4
count value reaches5
row=['']*3
row
['', '', '']
row=['']*3
table=[row]*3
for row in table:
print(row)
o/p
['', '', '']
['', '', '']
['', '', '']
row=['']*3
table=[row]*3
table[2][2]='X'
for row in table:
print(row)
o/p
['', '', 'X']
['', '', 'X']
['', '', 'X']
def fun(a,b):
print('function',a,b)
fun(2,3)
o/p
function 2 3
def fun(a,b,c=5):
print('function',a,b,c)
fun(2,3)
o/p
function 2 3 5
def add(a,b):
print('addition of %d and %d is %d.'%(a,b,a+b))
add(2,3)
o/p
addition of 2 and 3 is 5.
###write a function to calculate factorial of a number.the number will be
given through argument from user
def fact(a):
f=1
for i in range(1,a+1):
f=f*i
print(f)
fact(5)
###write a function to multiply all the numbers in a list
###write a fuction to convert all vowels to uppercase
srt=input()
y=str
vowels='aeiou'
for vowel in vowels:
y=y.replace(vowel, vowel.upper())
print(y)
##***## ARBITRARY FUNCTION
def arbitrary(x,y,*more):
print('x=', x, ', y=', y)
print('arbitrary: ', more)
arbitrary(3,4)
o/p
x= 3 , y= 4
arbitrary: ()
def arbitrary(x,y,*more):
print('x=', x, ', y=', y)
print('arbitrary: ', more)
arbitrary(3,4,'hello bdfliuhbds')
o/p
x= 3 , y= 4
arbitrary: ('hello bdfliuhbds',)
import time
>>> import datetime
>>> print('year',datetime.date.today().strftime('%Y'))
year 2019
>>> print('month',datetime.date.today().strftime('%B'))
month August
>>> print('day of year',datetime.date.today().strftime('%j'))
day of year 231
>>> print('day of month',datetime.date.today().strftime('%d'))
day of month 19
>>> print('day of week',datetime.date.today().strftime('%A'))
day of week Monday
import time
>>> import datetime
>>> dateobj=datetime.date.today().strftime('%m %d %Y %I:%M %p')
>>> print(dateobj)
08 19 2019 12:00 AM
import datetime
print(datetime.datetime.now().time())
o/p
15:45:24.470506
###Take input from user and give output of a float type addition
in a single statement
print('The sum is %.lf'%(float(input('Enter first number:'))+float(input('Enter second number'))))
####Switch case, program make a simple calculator that can add, subtract,
multiply, and divide using function
def add():
print('The sum is %.lf'%(float(input('Enter first number:'))+float(input('Enter second number'))))
def sub():
print('The difference is %.lf'%(float(input('Enter first number:'))-float(input('Enter second number'))))
def multi():
print('The product is %.lf'%(float(input('Enter first number:'))*float(input('Enter second number'))))
def div():
print('The quotient is %.lf'%(float(input('Enter first number:'))/float(input('Enter second number'))))
while True:
n=input('Enter\n1 for addition\n2 for subtraction\n3 for multiplication\n4 for division\nAny key for othe options\n')
if n=='1':
add()
elif n=='2':
sub()
elif n=='3':
multi()
elif n=='4':
div()
else:
c=0
c=input('Enter e to exit\nAny key to continue\n')
if c=='E':
break
else:
continue