-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweek_3.txt
167 lines (165 loc) · 9.16 KB
/
week_3.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
resource url?
QUESTION ----------------
Write a program to find the eligibility of admission for a professional course based on the following criteria:Marks in Maths >= 65Marks in Physics >= 55Marks in Chemistry >= 50OrTotal in all three subjects >= 180Sample Test CasesTest Case 1Input706080Output The candidate is eligibleTest Case 2 Input508080 OutputThe candidate is eligibleTest Case 3Input506040OutputThe candidate is not eligible
------------------ANSWER
m=int(input())
p=int(input())
c=int(input())
if (((m+p+c)>=180) or (m>=65 and p>=55 and c>=50)):
print("The candidate is eligible")
else:
print("The candidate is not eligible")
------------------------------
QUESTION ----------------
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 11900Sample Output 11900 is not a leap year.Sample Input 22000Sample Output 22000 is a leap year.
------------------ANSWER
y=int(input())
if y%400==0 or (y%100!=0 and y%4==0):
print(y,"is a leap year.")
else:
print(y,"is not a leap year.")
------------------------------
QUESTION ----------------
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 1iSample Output 1It's a vowel.Sample Input 2ySample Output 2Sometimes it's a vowel... Sometimes it's a consonant.Sample Input3cSample Output 3It's a consonant.
------------------ANSWER
ch=input()
if ch=='y':
print("Sometimes it's a vowel... Sometimes it's a consonant.")
elif ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u':
print("It's a vowel.")
else:
print("It's a consonant.")
------------------------------
QUESTION ----------------
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 1FebruarySample Output 1February has 28 or 29 days in it.Sample Input 2MarchSample Output 2March has 31 days in it.Sample Input 3AprilSample Output 3April has 30 days in it.
------------------ANSWER
m=input()
if m=="January" or m=="March" or m=="May" or m=="July" or m=="August" or m=="October" or m=="December" :
print(m,"has 31 days in it.",sep=' ')
elif m=="February" :
print(m,"has 28 or 29 days in it.",sep=' ')
elif m=="April" or m=="June" or m=="September" or m=="November" :
print(m,"has 30 days in it.",sep=' ')
------------------------------
QUESTION ----------------
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.
------------------ANSWER
y=int(input())
new=(y-2000)%12
if(new==0):
print(y,"is the year of the Dragon.")
elif(new==1):
print(y,"is the year of the Snake.")
elif(new==2):
print(y,"is the year of the Horse.")
elif(new==3):
print(y,"is the year of the Sheep.")
elif(new==4):
print(y,"is the year of the Monkey.")
elif(new==5):
print(y,"is the year of the Rooster.")
elif(new==6):
print(y,"is the year of the Dog.")
elif(new==7):
print(y,"is the year of the Pig." )
elif(new==8):
print(y,"is the year of the Rat.")
elif(new==9):
print(y,"is the year of the Ox.")
elif(new==10):
print(y,"is the year of the Tiger.")
elif(new==11):
print(y,"is the year of the Hare.")
------------------------------
QUESTION ----------------
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 1606060Sample Output 1That's a equilateral triangleSample Input 2404080Sample Output 2That's a isosceles triangleSample Input 3506070Sample Output 3That's a scalene triangle
------------------ANSWER
s1=int(input())
s2=int(input())
s3=int(input())
if s1==s2 and s2==s3:
print("That's a equilateral triangle")
elif (s1==s2 or s2==s3) or (s3==s1):
print("That's a isosceles triangle")
else:
print("That's a scalene triangle")
------------------------------
QUESTION ----------------
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
------------------ANSWER
n=abs(int(input()))
if n%10==n:
print(-1)
else:
n=n//10
print(n%10)
------------------------------
QUESTION ----------------
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
------------------ANSWER
s1=int(input())
s2=int(input())
if s2<(s1//2):
print("OUT")
elif s2>=(s1//2):
print("IN")
------------------------------
QUESTION ----------------
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". Please note that the
output message is in small letters.
Sample Input
3
5
4
Sample Output
yes
Sample Test Cases
Test Case 1
Input
3
5
4
Output
yes
Test Case 2
Input
5
8
2
Output
no
------------------ANSWER
a=int(input())
b=int(input())
c=int(input())
if (a**2 + b**2 == c**2) or (b**2 + c**2 == a**2) or (c**2 + a**2 == b**2):
print('yes')
else:
print('no')
------------------------------
QUESTION ----------------
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 / UnitUpto 199 @1.20200 and above but less than 400 @1.50400 and above but less than 600 @1.80600 and above @2.00If bill exceeds Rs.400 then a surcharge of 15% will be charged and the minimum bill should be of Rs.100/- Sample Test CasesTest Case 1 Input50 Output100.00 Test Case 2Input 300Output 517.50
------------------ANSWER
unit=float(input())
bill=0
if(unit<100):
bill=100
elif(unit>=100 and unit<199):
bill=unit*1.20
elif (unit>=200 and unit<400):
bill=unit*1.50
elif(unit>=400 and unit<600):
bill=unit*1.80
elif(unit>=600):
bill=unit*2.00
if(bill>400):
print("%.2f"%(bill+(bill*(15/100))))
else:
print("%.2f"%bill)
------------------------------