-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloopingtask.py
More file actions
409 lines (285 loc) · 8.85 KB
/
loopingtask.py
File metadata and controls
409 lines (285 loc) · 8.85 KB
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# 1.Wap to print n natural numbers
# n = eval(input("Enter the number: "))
# if type(n) == int:
# i=1
# while i<n:
# print(i)
# i=i+1
#----------------------------------------------
# 2.Wap to print n natural numbers in reverse order.
# n = eval(input("Enter the number: "))
# if type(n) == int:
# while n>0:
# print(n)
# n-=1
#--------------------------------------------------
# 3.Wap to print natural numbers in a given range
# start = eval(input("Enter the start number: "))
# end = eval(input("Enter the end number: "))
# if type(start) == int and type(end) ==int:
# while start<=end:
# print(start)
# start+=1
#------------------------------------------------------------------------------
# 4.Wap to print user name 10 times
# user = eval(input("Enter the namme: "))
# if type(user) == str:
# i=1
# while i<=10:
# print(user)
# i+=1
#-------------------------------------------------------------
# 5.Wap to print the multiplication table.
# table = int(input("Enter the number: "))
# if type(table) == int:
# i=1
# while i<=10:
# print(table,'x',i,'=',table*i)
# i+=1
#------------------------------------------------------------------
# 6.Wap to print n natural even numbers.
# n = eval(input("Enter the number: "))
# if type(n) == int:
# i=1
# while i<=n:
# if i%2==0:
# print(i,end=" ")
# i+=1
# n = eval(input("Enter the number: "))
# if type(n) == int:
# i=1
# while i<=n:
# if i%2 == 0:
# print(i)
# i+=1
#-----------------------------------------------------------------------------------------------------
# 7.Wap to print n natural odd numbers.
# n = eval(input("Enter the number: "))
# if type(n) == int:
# i=1
# while i<=n:
# if i%2!= 0:
# print(i)
# i+=1
#----------------------------------------------------------------------------------------------------------------
# 8.Wap to print n natural palindrome numbers
# n = eval(input("Enter the number: "))
# if type(n) == int:
# i=1
# while n==n-1:
# print(i)
# i+=1
#-----------------------------------------------------------------------------------------
# 9.Wap to print the sum of n natural number
# n = eval(input("Enter the number: "))
# i=1
# sum=0
# while i<=n:
# sum+=i
# i+=1
# print("The sum is :". sum)
#--------------------------------------------------------------------------------------------
# 10.Wap to print product of n natural numbers.
#
# 11.Wap to print factorial a number.
# n = int(input("Entewr the number :"))
# fact = 1
# i = 1
# while i<=n:
# fact = fact*i
# i+=1
# print("factorial of",n,"is",fact)
# 12.Wap to print the digits of a number
# 13.Wap to find the sum of digits of a number.
# n = int(input("Enter a number: "))
# add=0
# i=1
# while n>0:
# last_digit =n%10
# add+=last_digit
# n//=10
# print(add)
#----------------------------------------------------------
# 14.Wap to find the product of digits of a number.
# n=int(input("Enter the number :"))
# print("The digit of number are:")
# product=1
# while n>0:
# digits = n %10
# product*=digits
# n=n//10
# print("The product of digit is:",product)
#---------------------------------------------------------
# 15.Wap to reverse a number without using slicing
# n=int(input("Enter the number :"))
# rev=0
# while n>0:
# ld=n%10
# rev=rev*10+ld
# n//=10
# print(rev)
#------------------------------------------------------------------------
# 16.Wap to reverse a number without using type casting and slicing.
# n=int(input("Enter the number :"))
# rev=0
# while n>0:
# ld=n%10
# rev=rev*10+ld
# n//=10
# print(rev)
# 17.Wap to count the no. of zeros present in a number
# n=int(input("Enter the number :"))
# count=0
# while n>0:
# ld=n%10
# if ld==0:
# count+=1
# n//=10
# print("Count :",count)
#-------------------------------------------------------------
# 18.Wap to print the factors of a number.
# n=int(input("Enter the number :"))
# i=1
# while i<=n:
# if n%i==0:
# print(i)
# i+=1
#-----------------------------------------------------
# 19.Wap check the no. is prime or not
# n=int(input("Enter the number :"))
# if n<=1:
# print(n,"is not a prime number")
# else:
# i=2
# is_prime=True
# while i<n-1:
# 20.Wap to check the no. is Armstrong no. or not. #153,370
# n = int(input("Enter the number :"))
# if n>1:
# for i in range(2,n):
# if n%i==0:
# print(n,"is not a number")
# break
# else:
# print(n,"is a prime number")
# else:
# print(n,"is not a prime number")
#------------------------------------------------------------------
# 21.Wap to check the no. disarium no. or not. #89,135,175
# n = int(input("Enter the number :"))
# sum=0
# a=n
# while n>0:
# ld=n%10
# p=len(str(n))
# n//=10
# if sum==a:
# print(a,"is a disarium number")
# else:
# print(a,"is not a disarium number")
# 22.Wap to check the given number is a Harshad no. or not #36,18,132
# 23.Check the given no.is spy number or not. #1124,123,22
# 24.Wap to check the no. is perfect no. or not
# 25.Wap to check the no. is a strong no. or not.
# 26.Wap to check is xylem or phloem no.
# 27.Create a list of n no. values provided by the userś
# 28.Given a list of numbers, count how many are even and how many are odd.
# 29.Wap to print all the values of a collection (str, list, tuple)
# l=eval(input("Enter the list of collection:"))
# i=0
# while i<len(l):
# print(l[i], end=' ')
# i+=1
# 30.Wap to print the string values from a given a list
# st=eval(input("Enter the list :"))
# if type(st)==list:
# i=0
# while i<len(st):
# if type(st[i])==str:
# print(st[i])
# i+=1
# 31.Wap to extract all the palindrome word from a given list
# s1 = \[10,404,'hii',4.5,'eye',7-8j,'bye','madam',202]
# o/p= \['eye', 'madam']
# 32.Wap to print all the characters of a string
# 33.Wap to print all vowels present in a word
# 34.Wap to extract all the strings from a list.
# 35.Wap to extract all the palindrome no. from a list
# 36.Wap to return a tuple containing n natural odd numbers
# 37.Wap to print all the values of a set
# 38.Wap to extract all the float values from a set and store in a list
# 39.Wap to toggle the string
# 40.Wap to reverse the given word
# Nested loop :-
# ============
# 1. Wap to extract all the prime numbers from a given list
# 2. Wap to extract all the Armstrong number from a given list.
# 3. Wap to extract all the perfect numbers from a tuple
# 4. Wap to extract the xylem numbers from a list
#
# wap prduct of all the digits of a number
# n=int(input("Enter a number :"))
# pro =1
# while n>0:
# last_digit = n%10
# pro = pro*last_digit
# n = n//10
# print("Product of the digits :",pro)
# find the product odd digits and sum of even digit of a given number
# n=int(input("Enter a number :"))
# sum=0
# pro=1
# while n>0:
# ld=n%10
# if ld%2==0:
# sum+=ld
# else:
# pro*=ld
# n//=10
# print("sum:",sum)
# print("Product:",pro)
# wap to print all the character of a string
# s="Hello"
# print(s[0])
# print(s[1])
# print(s[2])
# print(s[3])
# print(s[4])
import time
from calendar import isleap
# judge the leap year
def judge_leap_year(year):
if isleap(year):
return True
else:
return False
# returns the number of days in each month
def month_days(month, leap_year):
if month in [1, 3, 5, 7, 8, 10, 12]:
return 31
elif month in [4, 6, 9, 11]:
return 30
elif month == 2 and leap_year:
return 29
elif month == 2 and (not leap_year):
return 28
name = input("input your name: ")
age = input("input your age: ")
localtime = time.localtime(time.time())
year = int(age)
month = year * 12 + localtime.tm_mon
day = 0
begin_year = int(localtime.tm_year) - year
end_year = begin_year + year
# calculate the days
for y in range(begin_year, end_year):
if (judge_leap_year(y)):
day = day + 366
else:
day = day + 365
leap_year = judge_leap_year(localtime.tm_year)
for m in range(1, localtime.tm_mon):
day = day + month_days(m, leap_year)
day = day + localtime.tm_mday
print("%s's age is %d years or " % (name, year), end="")
print("%d months or %d days" % (month, day))