-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevel2.py
More file actions
484 lines (394 loc) · 10.3 KB
/
Copy pathLevel2.py
File metadata and controls
484 lines (394 loc) · 10.3 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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# Problem 1
# Question : Write a loop program to print 1 to 5 on one by one.
# Output :
# 1
# 2
# 3
# 4
# 5
# for i in range(1,6):
# print(i)
#! Problem 2
# Question : Write a loop program to print 5 to 1 on one by one.
# Output :
# 5
# 4
# 3
# 2
# 1
# for i in range(5,0,-1):
# print(i)
#! Problem 3
# Question : Write a loop program to print sum of 1 to 5.
# Output : 15
# sum=0
# for i in range(1,6):
# sum=sum+i
# print(sum)
#! Problem 4
# Question : Write a loop program to print sum of 6 to 1.
# Output : 21
# sum=0
# for i in range(6,0,-1):
# # print(i)
# sum+=i
# print(sum)
#! Problem 5
# Question : Write a loop program to print odd numbers 1 to 9.
# Output :
# 1
# 3
# 5
# 7
# 9
# for i in range(1,10):
# if i%2!=0:
# print(i)
#! Problem 6
# Question : Write a loop program to print the two-digit odd numbers, below
# 20.
# Output :
# 11
# 13
# 15
# 17
# 19
# for i in range(11,20,2):
# print(i)
#! Problem 7
# Question : Write a loop program to print the two-digit odd numbers,
# who’s sum of digits are 7.
# Output :
# 25
# 43
# 61
# for i in range(10,100):
# if i%2!= 0:
# if ((i//10)+(i%10)==7):
# print(i)
#! Problem 8
# Question : Write a loop program to print the two-digit even numbers,
# who’s sum of digits are 6.
# Output :
# 24
# 42
# 60
# for i in range(10,100):
# if i%2==0:
# sum=(i//10)+(i%10)
# if sum==6:
# print(i)
#! Problem 9
# Question : Write a loop program to print the sum of two-digit numbers
# whose one’s digit is 5.
# Output : 495
# sum=0
# for i in range(15,100,10):
# sum=sum+i
# print(sum)
#! Problem 10
# Question : Write a loop program to print the sum of two-digit odd numbers,
# whose ten’s digit is 7.
# Output : 375
# sum=0
# for i in range(70,80):
# if i%2!=0:
# sum=sum+i
# print(sum)
#! Problem 11
# Question : Write a program to get a number from user print the total
# number of digits in that number
# Output :
# Input : 123456 - Output – 6
# Input : 76895439- Output – 8
# Input : 675 – Output - 3
# num=int(input("Enter a number: "))
# count=0
# for i in str(num):
# count=count+1
# print(count)
#! Problem 12
# Question :Write a program to get a number from user and print the sum
# of all digits.
# Output :
# Input: 123456 - Output – 21
# Input: 76895439 - Output – 51
# Input: 675 – Output - 18
# num=int(input("Enter a number: "))
# sum=0
# for i in str(num):
# sum=sum+int(i)
# print(sum)
#another method
# num=int(input("Enter a number: "))
# sum=0
# while num>0:
# digit=num%10
# sum+=digit
# num//=10
# print(sum)
#! Problem 13
# Question :Write a program to get a number from user and print the
# reverse of that number
# Output :
# Input : 123456 - Output – 654321
# Input : 76895439- Output – 93459867
# Input : 675 – Output - 576
# num=int(input("Enter a number: "))
# rev=0
# while num>0:
# digit=num%10
# rev=rev*10+digit
# num=num//10
# print(rev)
#! Problem 14
# Question : Write a program to get a number from user and interchange the
# first and last digits and print the result.
# Output :
# Input : 123456 - Output – 623451
# Input : 76895439- Output – 96895437
# Input : 675 – Output - 576
# num=input("Enter a number: ")
# print(num[-1]+num[1:-1]+num[0])
# another method
# num=int(input("Enter a number: "))
# temp=num
# count=0
# while temp>0:
# count+=1
# temp//=10
# first=num//(10**(count-1))
# last=num%10
# middle=(num%(10**(count-1)))//10
# result=last*(10**(count-1))+middle*10+first
# print(result)
#! Problem 15
# Question : Write a program to get a number from user and if the last digit of
# the number is even print the same number. If the last digit of the number is
# odd then subtract 1 from the last digit and print the number.
# (Note: Last digit -MSB)
# Output :
# Input : 123456 - Output – 023456 Input : 96895439- Output – 86895439
# Input : 675 – Output - 675 Input : 575 – Output - 475.
# num=int(input("Enter a number: "))
# temp=num
# count=0
# while temp>0:
# count+=1
# temp//=10
# first=num//(10**(count-1))
# last=num%10
# middle=(num%(10**(count-1)))//10
# if first%2==0:
# res=first*(10**(count-1))+middle*10+last
# print(res)
# else:
# res=(first-1)*(10**(count-1))+middle*10+last
# print(res)
#! Problem 16
# Question : Write a program get number from user print whether that number
# is prime or not.
# Output :
# Input : 31 - Output : Prime
# Input : 27 - Output : Not Prime
# num=int(input("Enter a number: "))
# count=0
# for i in range(1,num+1):
# if num%i==0:
# count+=1
# if count==2:
# print("Prime")
# else:
# print("Not Prime")
#! Problem 17
# Question : Write a program to get a number from user, print whether that
# number is prime, and sum of digit is equal to 14.
# Output :
# Input: 59 - Output: Prime & Sum of Digits is 14
# Input: 77 - Output: Not Prime but sum of digits is 14
# Input: 13 - Output: Prime, but sum of Digits is not 14
# num=int(input("Enter a number: "))
# temp=num
# sum=0
# count=0
# while temp>0:
# digit=temp%10
# sum+=digit
# temp//=10
# for i in range(1,num+1):
# if num%i==0:
# count+=1
# if count==2 and sum==14:
# print("Prime & Sum of Digits is 14")
# elif count==2 and sum!=14:
# print("Prime, but sum of digits is not 14")
# else:
# print("Not Prime but sum of digits is 14")
#! Program 18
# Question : Write a program to get number from user, print whether that
# number’s first two digits (ten’s digits and one’s digit) is prime.
# Output :
# Input: 359 - Output: Prime
# Input: 3577 - Output: Not Prime
# num=int(input("Enter a number: "))
# digits=num%100
# count=0
# for i in range(1,digits+1):
# if digits%i==0:
# count+=1
# if count==2:
# print("Prime")
# else:
# print("Not Prime")
#! Problem 19
# Question : Write a program to get a 4-digit number from user, print whether
# that number’s middle two digits (hundred’s digit and ten’s digit) is prime.
# Output :
# Input: 6359 - Output: Not Prime
# Input: 3517 - Output: Prime
# num=int(input("Enter a four-digit number: "))
# middle=(num//10)%100
# count=0
# for i in range(1,middle+1):
# if middle%i==0:
# count+=1
# if count==2:
# print("Prime")
# else:
# print("Not prime")
#! Problem 20
# Question : Write a program print total number of single digit Prime numbers
# Output : 4
# count=0
# for i in range(2,10):
# factors=0
# for j in range(1,i+1):
# if i%j==0:
# factors+=1
# if factors==2:
# count+=1
# print(count)
#! Problem 21
# Question : Write a program get number from user print the total number
# digits which are odd in the number.
# Output :
# Input : 12345678 - Output : 4
# Input : 987531 - Output : 5
# num=int(input("Enter a number: "))
# count=0
# while num>0:
# digit=num%10
# if digit%2!=0:
# count+=1
# num//=10
# print(count)
#! Problem 22
# Question : Write a program get number from user print the total number
# of two-digit odd numbers in the number.
# Output :
# Input: 12345678 - Output: 3
# Input: 987531 - Output: 4
# num=int(input("Enter a number: "))
# count=0
# while num>10:
# digit=num%100
# if digit%2!=0:
# count=count+1
# num//=10
# print(count)
#! Problem 23
# Question : Write a program get number from user print the total number
# of single-digit perfect square numbers in the number.
# Output :
# Input: 123456789 - Output: 3
# Input: 987531 - Output: 2
# num=int(input("Enter a number: "))
# count=0
# while num>0:
# digit=num%10
# if digit==1 or digit==4 or digit==9:
# count=count+1
# num=num//10
# print(count)
#! Problem 24
# Question :Write a program get number from user print the total number
# of two-digit perfect square numbers in the number.
# Output :
# Input: 163496481 - Output: 4
# Input: 364925 - Output: 4
# num=int(input("Enter a number: "))
# count=0
# while num>=10:
# digit=num%100
# if digit==16 or digit==25 or digit==36 or digit==49 or digit==64 or digit==81:
# count+=1
# num//=10
# print(count)
#! Problem 25
# Question : Write a program get number from user print the total number of
# single-digit prime numbers in the number.
# Output :
# Input: 163496481 - Output: 1
# Input: 364925 - Output: 3
# num=int(input("Enter a number: "))
# count=0
# while num>0:
# digit=num%10
# if digit==2 or digit==3 or digit==5 or digit==7:
# count+=1
# num//=10
# print(count)
#! Problem 26
# Question : Write a program to print biggest 4-digit number which is
# divisible by 7 and 9
# for i in range(9999,999,-1):
# if i%7==0 and i%9==0:
# print(i)
# break
#! Problem 27
# Question :Write a program to print the total count of numbers which are
# less than 100000 and whose sum of digits is 14.
# count=0
# for i in range(1,100000):
# temp=i
# sum=0
# while temp>0:
# digit=temp%10
# sum=sum+digit
# temp//=10
# if sum==14:
# count=count+1
# print(count)
#! Problem 28
# Question : Write a program to get two numbers from user and print the
# LCM of those numbers.
# num1=int(input("Enter a number: "))
# num2=int(input("Enter a number: "))
# max_num=max(num1,num2)
# while True:
# if max_num%num1==0 and max_num%num2==0:
# print("LCM of two number is:",max_num)
# break
# max_num=max_num+1
#! Problem 29
# Question :Write a program to get three numbers from user and print the
# LCM of those numbers.
# num1=int(input("Enter a number: "))
# num2=int(input("Enter a number: "))
# num3=int(input("Enter a number: "))
# max_num=max(num1,num2,num3)
# while True:
# if max_num%num1==0 and max_num%num2==0 and max_num%num3==0:
# print("LCM of three numbers is", max_num)
# break
# max_num+=1
#! Problem 30
# Question : Write a program to get two numbers from user and print the
# HCF of those numbers.
# num1=int(input("Enter a number: "))
# num2=int(input("Enter a number: "))
# min_num=min(num1,num2)
# for i in range(min_num,0,-1):
# if num1%i==0 and num2%i==0:
# print("HCF of two numbers is ",i)
# break