-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeek 3.py
More file actions
517 lines (325 loc) · 9.54 KB
/
Copy pathWeek 3.py
File metadata and controls
517 lines (325 loc) · 9.54 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
3.1 Admission Eligibility
Write a program to find the eligibility of admission for a professional course based on the following criteria:
Marks in Maths >= 65
Marks in Physics >= 55
Marks in Chemistry >= 50
Or
Total in all three subjects >= 180
Sample Test Cases
Test Case 1
Input
70
60
80
Output
The candidate is eligible
Test Case 2
Input
50
80
80
Output
The candidate is eligible
Test Case 3
Input
50
60
40
Output
The candidate is not eligible
For example:
Input Result
50
80
80 The candidate is eligible
a=int(input())
b=int(input())
c=int(input())
if(a>=65 and b>=55 and c>=50):
print("The candidate is eligible")
elif(a+b+c>=180):
print("The candidate is eligible")
else:
print("The candidate is not eligible")
3.2
Classifying Triangles
A triangle can be classified based on the lengths of its sides as equilateral, isosceles or scalene. All three sides of an equilateral triangle have the same length. An isosceles triangle has two sides that are the same length, and a third side that is a different length. If all of the sides have different lengths then the triangle is scalene.
Write a program that reads the lengths of the three sides of a triangle from the user. Then display a message that states the triangle’s type.
Sample Input 1
60
60
60
Sample Output 1
That's a equilateral triangle
For example:
Input Result
40
40
80 That's a isosceles triangle
a=int(input())
b=int(input())
c=int(input())
if(a==b and b==c):
print("That's a equilateral triangle")
elif(a!=b and b==c or a==b and b!=c):
print("That's a isosceles triangle")
elif(a!=b and b!=c):
print("That's a scalene triangle")
3.3
Electricity Bill
Write a program to calculate and print the Electricity bill where the unit consumed by the user is given from test case. It prints the total amount the customer has to pay. The charge are as follows:
Unit Charge / Unit
Upto 199 @1.20
200 and above but less than 400 @1.50
400 and above but less than 600 @1.80
600 and above @2.00
If bill exceeds Rs.400 then a surcharge of 15% will be charged and the minimum bill should be of Rs.100/-
Sample Test Cases
Test Case 1
Input
50
Output
100.00
Test Case 2
Input
300
Output
517.50
For example:
Input Result
500 1035.00
a=float(input())
b=0
if(a<=199):
b=a*1.2
elif(200<=a<400):
b=a*1.5
elif(400<=a<600):
b=a*1.8
elif(a>600):
b=a*2.0
if (int(b)<100):
print("{:.2f}".format(100))
else:
if(b>400.00):
print("{:.2f}".format((b+(b*0.15))))
else:
print("{:.2f}".format(b))
3.4
IN/OUT
Ms. Sita, the faculty handling programming lab for you is very strict. Your seniors have told you that she will not allow you to enter the week's lab if you have not completed atleast half the number of problems given last week. Many of you didn't understand this statement and so they requested the good programmers from your batch to write a program to find whether a student will be allowed into a week's lab given the number of problems given last week and the number of problems solved by the student in that week.
Input Format:
Input consists of 2 integers.
The first integer corresponds to the number of problems given and the second integer corresponds to the number of problems solved.
Output Format:
Output consists of the string “IN” or “OUT”.
Sample Input and Output:
Input
8
3
Output
OUT
For example:
Input Result
8
3 OUT
a=int(input())
b=int(input())
c=(a/2)
if(c>b):
print("OUT")
else:
print("IN")
3.5
Vowel or Consonant
In this exercise you will create a program that reads a letter of the alphabet from the user. If the user enters a, e, i, o or u then your program should display a message indicating that the entered letter is a vowel. If the user enters 'y' then your program should display a message indicating that sometimes y is a vowel, and sometimes y is a consonant. Otherwise your program should display a message indicating that the letter is a consonant.
Sample Input 1
i
Sample Output 1
It's a vowel.
Sample Input 2
y
Sample Output 2
Sometimes it's a vowel... Sometimes it's a consonant.
Sample Input3
c
Sample Output 3
It's a consonant.
For example:
Input Result
y Sometimes it's a vowel... Sometimes it's a consonant.
u It's a vowel.
p It's a consonant.
a=input()
if(a=='a' or a=='e' or a=='i' or a=='o' or a=='u'):
print("It's a vowel.")
elif(a=='y'):
print("Sometimes it's a vowel... Sometimes it's a consonant.")
else:
print("It's a consonant.")
3.6
Leap Year
Most years have 365 days. However, the time required for the Earth to orbit the Sun is actually slightly more than that. As a result, an extra day, February 29, is included in some years to correct for this difference. Such years are referred to as leap years. The rules for determining whether or not a year is a leap year follow:
• Any year that is divisible by 400 is a leap year.
• Of the remaining years, any year that is divisible by 100 is not a leap year.
• Of the remaining years, any year that is divisible by 4 is a leap year.
• All other years are not leap years.
Write a program that reads a year from the user and displays a message indicating whether or not it is a leap year.
Sample Input 1
1900
Sample Output 1
1900 is not a leap year.
Sample Input 2
2000
Sample Output 2
2000 is a leap year.
year=int(input())
if(year%400==0):
print(year,"is a leap year.")
else:
print(year,"is not a leap year.")
3.7
Month name to days
The length of a month varies from 28 to 31 days. In this exercise you will create a program that reads the name of a month from the user as a string. Then your program should display the number of days in that month. Display “28 or 29 days” for February so that leap years are addressed.
Sample Input 1
February
Sample Output 1
February has 28 or 29 days in it.
Sample Input 2
March
Sample Output 2
March has 31 days in it.
Sample Input 3
April
Sample Output 3
April has 30 days in it.
For example:
Input Result
February February has 28 or 29 days in it.
March March has 31 days in it.
m=input()
if(m=="January"):
print(m,"has 31 days in it.")
elif(m=="February"):
print(m,"has 28 or 29 days in it.")
elif(m=="March"):
print(m,"has 31 days in it.")
elif(m=="April"):
print(m,"has 30 days in it.")
elif(m=="May"):
print(m,"has 31 days in it.")
elif(m=="June"):
print(m,"has 30 days in it.")
elif(m=="July"):
print(m,"has 31 days in it.")
elif(m=="August"):
print(m,"has 31 days in it.")
elif(m=="September"):
print(m,"has 30 days in it.")
elif(m=="October"):
print(m,"has 31 days in it.")
elif(m=="November"):
print(m,"has 30 days in it.")
elif(m=="December"):
print(m,"has 31 days in it.")
3.8
Pythagorean triple
Three numbers form a Pythagorean triple if the sum of squares of two numbers is equal to the square of the third.
For example, 3, 5 and 4 form a Pythagorean triple, since 3*3 + 4*4 = 25 = 5*5
You are given three integers, a, b, and c. They need not be given in increasing order. If they form a Pythagorean triple, then print "Yes", otherwise, print "No".
Sample Input
3
5
4
Sample Output
Yes
For example:
Input Result
3
4
5 Yes
a=int(input())
b=int(input())
c=int(input())
if(a*a+b*b==c*c):
print("yes")
elif(a*a+c*c==b*b):
print("yes")
elif(c*c+b*b==a*a):
print("yes")
else:
print("no")
3.9
Second last digit
Write a program that returns the second last digit of the given number. Second last digit is being referred 10the digit in the tens place in the given number.
For example, if the given number is 197, the second last digit is 9.
Note1 - The second last digit should be returned as a positive number. i.e. if the given number is -197, the second last digit is 9.
Note2 - If the given number is a single digit number, then the second last digit does not exist. In such cases, the program should return -1. i.e. if the given number is 5, the second last digit should be returned as -1.
For example:
Input Result
197 9
a=int(input())
b=str(abs(a))
l=len(b)
if(l>1):
print(int(b[-2]))
else:
print(-1)
3.10
Chinese Zodiac
The Chinese zodiac assigns animals to years in a 12 year cycle. One 12 year cycle is shown in the table below. The pattern repeats from there, with 2012 being another year of the dragon, and 1999 being another year of the hare.
Year Animal
2000 Dragon
2001 Snake
2002 Horse
2003 Sheep
2004 Monkey
2005 Rooster
2006 Dog
2007 Pig
2008 Rat
2009 Ox
2010 Tiger
2011 Hare
Write a program that reads a year from the user and displays the animal associated with that year. Your program should work correctly for any year greater than or equal to zero, not just the ones listed in the table.
Sample Input 1
2010
Sample Output 1
2010 is the year of the Tiger.
Sample Input 2
2020
Sample Output 2
2020 is the year of the Rat.
a=int(input())
b=a%100
c=b%12
if(c==0):
print(a,"is the year of the Dragon.")
elif(c==1):
print(a,"is the year of the Snake.")
elif(c==2):
print(a,"is the year of the Horse.")
elif(c==3):
print(a,"is the year of the Sheep.")
elif(c==4):
print(a,"is the year of the Monkey.")
elif(c==5):
print(a,"is the year of the Rooster.")
elif(c==6):
print(a,"is the year of the Dog.")
elif(c==7):
print(a,"is the year of the Pig.")
elif(c==8):
print(a,"is the year of the Rat.")
elif(c==9):
print(a,"is the year of the Ox.")
elif(c==10):
print(a,"is the year of the Tiger.")
elif(c==11):
print(a,"is the year of the Hare.")