-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.py
More file actions
610 lines (471 loc) · 10.4 KB
/
Copy pathpractice.py
File metadata and controls
610 lines (471 loc) · 10.4 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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
x=3
y=5
#print(x*y)
#print(x**y)
#print(x/y)
#print(x//y)
#print(x%y)
#r=2
#i=5
#print(pi*r*r)
#l=5
#b=8
#print(l*b)
#radius=5
#pie=2
#areaOfCircle=pie*radius*radius
#print(areaOfCircle)
#lenght=4
#breadth=8
#areaOfRectangle=lenght*breadth
#print(areaOfRectangle)
#lenght=int(input('lenght is '))
#breadth=int(input('breadth is '))
#areaOfRectangle=lenght*breadth
#print(areaOfRectangle)
# x=int(input('value is '))
# if x%2==0:
# print('even')
# else:
# print('odd')
#grade calculator
# take value from user as a marks between (0-100)
#>= 90--> grade A
#>= 75--> grade B and < 90--> grade B
#>= 60--> grade C and < 75--> grade C
#< 60--> fail
# x=int(input('Enter the marks '))
# if x>=90:
# print('Grade A')
# elif (x>=75) and (x<90):
# print('Grade B')
# elif (x>=60) and (x<75):
# print('Grade C')
# else:
# print('Fail')
#Electricity Bill Calculator
#Units consumed:
#First 100 units 5/unit
#Next 100 units 7/unit
#Above 200 units 10/unit
#Take units as input and print the total bill.
# x=int(input('Unit Consumed '))
# if x<=100:
# print(x*5)
# elif (x<=200) and (x>100):
# print(100*5+x*7)
# else:
# print(100*5+100*7+(x-200)*10)
# Simple Calculator
# Take:
# two numbers
# an operator (+,-,*,/)
# Perform the operation.
# Edge case: Handle division by zero using if
# x=int(input('value is '))
# y=int(input('value is '))
# opp=input('opperator is: ')
# if opp=='+':
# print(x+y)
# elif opp=="-":
# print(x-y)
# elif opp=='/':
# print(x/y)
# elif opp=='*':
# print(x*y)
# elif x=='0':
# print
# Atm Withdrawl Problem
# Take:
# account balance
# withdrawal amount
# Conditions:
# Amount must be multiple of 100
# Amount ≤ balance
# Minimum balance after withdrawal should be ₹500
# Print Success or Failure message.
#take withdrawl amount from user amount must be multple of 100
# x=10000
# withdrawl=int(input('withdrawl amount '))
# if (withdrawl%100==0) and (withdrawl<=x-500):
# print('withdrawl succesful')
# else:
# print('withdrawl failed')
# Final challenge
# Take product price
# If price > 5000 → 20% discount
# If price > 3000 → 10% discount
# Else → No discount
# Print final price using round()
# productprice=float(input('Product amount is '))
# discount20=(20/100)*productprice
# discount10=(10/100)*productprice
# if productprice>5000:
# print('you need to pay', round(productprice-discount20, 2))
# elif productprice>3000 and productprice<5000:
# print('you need to pay', round(productprice-discount10))
# else:
# print('no discount applied')
# Age Eligibility and Type Conversion
# Ask the user to enter their birth year as a string. Convert it to an integer and calculate their age (assume the current year is 2026).
# Using comparison and logical operators, check if the person is both:
# * 18 years or older
# * Age less than or equal to 60
# Print the age and whether the person is in the “working age group”.
# yearOfBirth=int(input('enter your birth year '))
# currentyear=2026
# age=currentyear-yearOfBirth
# print(age)
# if (age>=18) and (age<=60):
# print('you are in the working age group')
# else:
# print('you are NOT working in age group')
# Mobile Data Usage Bill
# Ask the user to input total data used in GB (float).
# Convert if required. Calculate the base bill at 50 per GB.
# If usage is greater than 10 GB and less than or equal to 25 GB, give 8% discount; if greater than 25 GB, give 12% discount.
# Also add 18% tax if final amount is greater than 1000 using logical operators. Print usage and final bill.
# dataUsage=float(input('enter your data usage: '))
# baseBill=dataUsage*50
# if (dataUsage>10) and (dataUsage>=25):
# discount=baseBill*0.08
# elif dataUsage>25:
# discount=baseBill*0.12
# finalbill=baseBill-discount
# if finalbill>=1000:
# tax=finalbill*0.18
# print('total data usage ',dataUsage)
# print('final bill pay ',finalbill)
# def discountCalculator(total):
# if (amount>=1000) and (quantity>5):
# discount=(total-(total*0.10))
# print(discount)
# else:
# print(total)
# amount=int(input('enter the amount: '))
# quantity=int(input('enter the quantity '))
# total=amount*quantity
# discountCalculator(total)
#1.
# x=1
# while x<=10:
# print(x)
# x=x+1
#2.
# x=2
# while x<=10:
# print(x)
# x=x+2
#3.
# x=123
# cnt=0
# while x>0:
# x=x//10
# print(x)
# cnt=cnt+1
# print(cnt)
# x=123456
# cnt=0
# while x>0:
# x=x//10
# cnt=cnt+1
# print(cnt)
#4.
# x=345678
# sum=0
# while x>0:
# rem=x%10
# sum=sum+rem
# x=x//10
# print(sum)
# x=12345
# sum=0
# while x>0:
# rem=x%10
# sum=sum+rem
# x=x//10
# print(sum)
#5.
# x=34567
# mul=0
# while x>0:
# rem=x%10
# mul=mul*10+rem
# print(mul)
# x=x//10
# print(mul)
# x=98765
# mul=0
# while x>0:
# rem=x%10
# mul=mul*10+rem
# print(mul)
# x=x//10
# print(mul)
#6.
# x=25
# mul=1
# while mul<=10:
# print(mul*x)
# mul=mul+1
#8.
# pos=0
# neg=0
# #num=int(input('enter the num (enter 0 to stop): '))
# while num!=0:
# if num>0:
# pos=pos+1
# else:
# neg=neg+1
# num=int(input('enter the num (enter 0 to stop): '))
# print('positive num are: ',pos)
# print('negative num are: ',neg)
# Print numbers until user enters 0
# num=int(input('enter the num (stop to enter 0): '))
# while num!=0:
# print(num)
# num=int(input('enter the num (stop to enter 0): '))
#8.
# Count positive and negative numbers
# positive=0
# negative=0
# num=int(input('enter the num (stop to enter 0): '))
# while num!=0:
# if num>0:
# positive=positive+1
# else:
# negative=negative+1
# num=int(input('enter the num (stop to enter 0): '))
# print('positive num are:',positive)
# print('negative num are:',negative)
#10.
#find factorial of a number
# num=int(input('enter the num: '))
# factor=1
# x=1
# while x<=num:
# factor=factor*x
# print(factor)
# x=x+1
# print(factor)
#11.
# num=121
# sum=0
# x=num
# while num>0:
# rem=num%10
# sum=sum*10+rem
# num=num//10
# print(sum)
# if x==sum:
# print('this is palindrome num')
# else:
# print('this is not palindrone')
#11.
#Check if a number is prime
# num=int(input('enter the num: '))
# x=2
# flag=True
# while x>num:
# if num%x==0:
# flag=False
# break
# x=x+1
# print(flag)
# if flag==False:
# print('no prime no.')
# else:
# print('prime no.')
#12.
# num=int(input('enter the num: '))
# odd=0
# even=0
# while num>0:
# rem=num%10
# if rem%2==0:
# even=even+rem
# else:
# odd=odd+rem
# num=num//10
# print('odd num are:',odd)
# print('even num are:',even)
#13.
#find the largest digit in a num
# num=int(input('enter the num: '))
# num=1123
# maxi=max
# while num>0:
# rem=num%10
# maxi=max(maxi,rem)
# num=num//10
# print(maxi)
# Count numbers divisible by 3 until -1
# num=int(input("Enter a number (-1 to stop): "))
# cnt=0
# while num>0:
# num = int(input("Enter a number (-1 to stop): "))
# if num%3==0:
# cnt=cnt+1
# if num==-1:
# break
# print("Count of numbers divisible by 3:", cnt)
#num=120
# x=1
# while x<=num:
# if num%x==0:
# print(x)
# x=x+1
# x=int(input('enter the num 1: '))
# y=int(input('enter the num 2: '))
# cnt=1
# gcd=1
# while cnt<=x and cnt<=y:
# rem1=x%cnt
# rem2=y%cnt
# if rem1==0 and rem2==0:
# gcd=cnt
# cnt=cnt+1
# print(gcd*x*y)
# num1=13
# num2=15
# i=2
# lcm=1
# while i<=(num1*num2):
# if i%num1==0 and i%num2==0:
# lcm=i
# break
# i =i+1
# print(lcm)
# n=12345697
# maxNum=0
# while n>0:
# lastDigit=n%10
# if maxNum<lastDigit:
# maxNum=lastDigit
# n=n//10
# print(maxNum)
# vowel='aeiou'
#
# name='iuytdrtuyiuo'
# #print(len(name))
# length=len(name)
# vowel='aeiou'
# i=0
# cnt=0
# while i < length:
# if name[i] in vowel:
# cnt=cnt+1
# i=i+1
# print(cnt)
# vowel='aeiou'
# name='vipin'
# lenth=len(name)
# x=0
# cnt=0
# while x<lenth:
# if (name[x]!='a') or (name[x]!='e') or (name[x]!='e') or (name[x]!='i') or (name[x]!='o') or (name[x]!='u'):
# cnt=cnt+1
# x=x+1
# print(cnt)
# vowel='aeiou'
# name='vipin'
# lenth=len(name)
# x=0
# cnt=0
# while x<lenth:
# if name[x] not in vowel:
# cnt=cnt+1
# x=x+1
# print(cnt)
# x=' ssEJDFpfrklwed '
# print(x.upper())
# print(x.lower())
# print(x.strip())
# print(x.replace('ss','rr'))
# print(x.split())
# print(x.find('J'))
# print(x.startswith('t'))
# print(x.endswith('h'))
# vowel='aeiou'
# name='vipin'
# lenth=len(name)
# # x=0
# cnt=0
# for vowel in name:
# if name[x] in vowel:
# cnt=cnt+1
# # x=x+1
# print(cnt)
# name='vipin'
# x=""
# for ch in name:
# x=ch+x
# # print(x)
# if x==name:
# print('palindrome')
# else:
# print('not palindrome')
# name='vipin'
# upper=0
# lower=0
# for ch in name:
# if (ch>='A') and (ch<='Z'):
# upper=upper+1
# elif (ch>='a') and (ch<='z'):
# lower=lower+1
# print('upper case are:',upper)
# print('lower case are:',lower)
#. Find frequency of each character.
# name='vipin'
# for ch in name:
# print(ch,'=',name.count(ch))
# name='my name is vipin'
# replace=""
# for ch in name:
# if ch==" ":
# replace=replace+"_"
# else:
# 0
# print(replace)
# name='vipi2345n'
# digits=0
# alphabet=0
# for ch in name:
# if (ch>='1') and (ch<='9'):
# digits=digits+1
# elif (ch>='a') and (ch<='z'):
# alphabet=alphabet+1
# elif (ch>='A') and (ch<='Z'):
# alphabet=alphabet+1
# print('digits are:',digits)
# print('alphabets are:',alphabet)
# name='vipin'
# x=''
# for ch in name:
# if ch not in 'aeoiu':
# x=x+ch
# print(x)
#GUESSING GAME
# import random
# x=random.randrange(1,10)
# guess=int(input('enter the value: '))
# while x!=guess:
# if x>guess:
# print('input a big value')
# guess=int(input('enter the value: '))
# elif x<guess:
# print('input a small value')
# guess=int(input('enter the value: '))
# else:
# break
# print('you guess it right')
# x='vipin'
# for ch in x:
# print(ch,'=',x.count(ch))
# Basic Python program: find 2 largest numbers in a list
x = [10, 5, 20, 5643, 3, 20]
unique = sorted(set(x), reverse=True)
first = unique[0]
second = unique[1]
print("Largest number :", first)
print("Second largest :", second)