-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise2.py
More file actions
234 lines (212 loc) · 5.94 KB
/
Exercise2.py
File metadata and controls
234 lines (212 loc) · 5.94 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
>>>age=int(21)
>>>print(age)
21
>>> height=float(1)
>>> print(height)
1.0
>>> a= 1+3j
>>> print(a)
(1+3j)
>>> b=int(input("Enter base: "))
Enter base: 20
>>> h=int(input("Enter height: "))
Enter height: 10
>>> area = 0.5*b*h
>>> print("The area of the triangle is ",area)
The area of the triangle is 100.0
>>> a = int (input("Enter side a:"))
Enter side a:5
>>> b = int (input("Enter side b:"))
Enter side b:4
>>> c = int (input("Enter side c:"))
Enter side c:3
>>> perimeter = a+b+c
>>> print("The perimeter of the traingle is",perimeter)
The perimeter of the traingle is 12
>>> length=int(input())
10
>>> width=int(input())
20
>>> area=length * width
>>> perimeter= 2*(length * width)
>>> print ("area: ",area, "perimeter: ",perimeter)
area: 200 perimeter: 400
>>> r=7
>>> pi=3.14
>>> a=pi*(r**2)
>>> c=2*pi*r
>>> print('area: ',r , 'circumference:',c)
area: 7 circumference: 43.96
>>> a=3.14*(7**2)
>>> print(a)
153.86
# Calculate the slope, x-intercept and y-intercept of y=2x-2
>>> slope=2
>>> y=-2
>>> x= -y/slope
>>> print(f'slope:',slope)
slope: 2
>>> print(f'y_intercept:',y)
y_intercept: -2
>>> print(f'x-intercept:',x)
x-intercept: 1.0
#Slope is (m = y2-y1/x2-x1). Find the slope and Euclidean distance between point (2, 2) and point (6,10)
>>> x1,y1,x2,y2 = 2,2,6,10
>>> m= (y2-y1)/(x2-x1)
>>> d= ((x2-x1)**2 + (y2-y1)**2)**0.5
>>> print('slope:',m)
slope: 2.0
>>> print('Euclidea distance:',d)
Euclidea distance: 8.94427190999916
# compared both the slopes
>>> if slope==m:
... print("Both the slopes are equal")
... else:
... print("The slopes are different")
...
Both the slopes are equal
#Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is going to be 0.
>>> x=-3
>>> y=x**2 +6*x+9
>>> print(y)
0
>>> len('python')
6
>>> len('dragon')
6
>>> n= len('python')
>>> p= len('dragon')
>>> print(n,p)
6 6
>>> if n==p:
... print("false")
... else:
... print("true")
...
false
>>> r=("on"in "python" and "dragon")
>>> print(r)
dragon
>>> r=('on'in'python')and('on'in'dragon')
>>> print(r)
True
>>> q="I hope this course in not full of jargoan"
>>> q=("jargoan"in"I hope this course in not full of jargoan")
>>> print(q)
True
>>> if "on"in"python" and "on"in"dragon":
... print("there is no 'on' in both dragon and python")
... else:
... print("")
...
there is no 'on' in both dragon and python
>>> a=len('python')
>>> b=float(a)
>>> c=str(b)
>>> print(a)
6
>>> print(b)
6.0
>>> print(c)
6.0
>>> num=int(input("Enter a number:"))
Enter a number:10
>>> if num % 2 == 0:
... print("even")
... else:
... print("not even")
...
even
>>> n=2.7
>>> a=int(n)
>>> b=7//3
>>> print(a)
2
>>> print(b)
2
>>> if a==b:
... print("same")
... else:
... print("not same")
...
same
>>> if type('10') == type(10):
... print("equal")
... else:
... print("not equal")
...
not equal
>>> if int('9.8')==10:
... print()
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '9.8'
a=int(input("Enter hours"))
Enter hours 40
>>> b=int(input("Enter rate per hour:"))
Enter rate per hour:28
>>> c=a*b
>>> print("your weekly earning is"c)
your weekly earning is 1120
>>> a=int(input("Enter number of years you have lived: "))
Enter number of years you have lived: 100
>>>
>>> sec=60
>>> min=60
>>> hours=24
>>> daysin_y=365
>>> c=a*sec*min*hours*daysin_y
>>> print('you have lived for',c,'seconds')
you have lived for 3153600000 seconds
>>> for i in range(1,6):
... print(i,i**0,i**1,i**2,i**3)
...
1 1 1 1 1
2 1 2 4 8
3 1 3 9 27
4 1 4 16 64
5 1 5 25 125
"""
Questions.
1.Declare your age as integer variable
2.Declare your height as a float variable
3.Declare a variable that store a complex number
4.Write a script that prompts the user to enter base and height of the triangle and calculate an area of this triangle (area = 0.5 x b x h).
Enter base: 20
Enter height: 10
The area of the triangle is 100
5.Write a script that prompts the user to enter side a, side b, and side c of the triangle. Calculate the perimeter of the triangle (perimeter = a + b + c).
Enter side a: 5
Enter side b: 4
Enter side c: 3
6.The perimeter of the triangle is 12
7.Get length and width of a rectangle using prompt. Calculate its area (area = length x width) and perimeter (perimeter = 2 x (length + width))
8.Get radius of a circle using prompt. Calculate the area (area = pi x r x r) and circumference (c = 2 x pi x r) where pi = 3.14.
9.Calculate the slope, x-intercept and y-intercept of y = 2x -2
10.Slope is (m = y2-y1/x2-x1). Find the slope and Euclidean distance between point (2, 2) and point (6,10)
11.Compare the slopes in tasks 8 and 9.
12.Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is going to be 0.
13.Find the length of 'python' and 'dragon' and make a falsy comparison statement.
14.Use and operator to check if 'on' is found in both 'python' and 'dragon'
15.I hope this course is not full of jargon. Use in operator to check if jargon is in the sentence.
16.There is no 'on' in both dragon and python
17.Find the length of the text python and convert the value to float and convert it to string
18.Even numbers are divisible by 2 and the remainder is zero. How do you check if a number is even or not using python?
19.Check if the floor division of 7 by 3 is equal to the int converted value of 2.7.
20.Check if type of '10' is equal to type of 10
21.Check if int('9.8') is equal to 10
22.Write a script that prompts the user to enter hours and rate per hour. Calculate pay of the person?
Enter hours: 40
Enter rate per hour: 28
Your weekly earning is 1120
23.Write a script that prompts the user to enter number of years. Calculate the number of seconds a person can live. Assume a person can live hundred years
Enter number of years you have lived: 100
You have lived for 3153600000 seconds.
24.Write a Python script that displays the following table
1 1 1 1 1
2 1 2 4 8
3 1 3 9 27
4 1 4 16 64
5 1 5 25 125
"""