Repository navigation
Expand file tree
/
Copy pathbasic.py
More file actions
301 lines (255 loc) · 4.58 KB
/
Copy pathbasic.py
File metadata and controls
301 lines (255 loc) · 4.58 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
# write a program to convert fahrenheit to celsius
f=float(input("enter the fahrenheit"))
c=(f-32)*5/9
print(" the celsius",c)
output:
enter the fahrenheit98
the celsius 36.666666666666664
# write a program to find simple interest
p=float(input("enter the P value",))
t=float(input("enter the T value"))
r=float(input("enter the R value"))
SI=(p*t*r)/100
print(SI)
output:
enter the P value123
enter the T value20
enter the R value10
246.0
# write a program to find area and perimeter of rectangle
l=float(input("enter l"))
b=float(input("enter b"))
a=l*b
b=2*(l+b)
print("area",a)
print("perimeter",b)
output:
enter l3
enter b4
area 12.0
perimeter 14.0
# write a program to find area and circumference of a circle
r=float(input("enter radius"))
a=r*r*3.14
c=2*3.14*r
print(a)
print(c)
output:
enter radius5
78.5
31.400000000000002
# write a program to find the speed of a vehicle
d=float(input("enter the distance in kms"))
t=float(input("enter the time min"))
s=d/t
print(s,"kmph")
output:
enter the distance in kms60
enter the time min60
1.0 kmph
# write a program to check whether triangular is valid or not if sides are given
a=float(input("enter a"))
b=float(input("enter b"))
c=float(input("enter c"))
if a+b>c and a+c>b and b+c>a:
print("triangle is valid")
else:
print("triangle is not valid")
output:
enter a5
enter b7
enter c10
triangle is valid
# check the given number is even or odd
a=float(input("enter a"))
if a==2:
print("given number is even")
else:
print("the number is odd")
output:
enter a5
the number is odd
# check the given alphabet is vowel or consonant
a=(input("enter the alphabet"))
if a=='a' or a=='e' or a=='i' or a=='o' or a=='u':
print("vowel")
else:
print("consonant")
output:
enter the year2024
is leap year
# write a program to determine the grade based on marks
a=float(input("enter the marks"))
if a>=90:
print("grade a")
elif a>=80 and a<=90:
print("grade b")
elif a>=70 and a<=80:
print("grade c")
elif a>=60 and a<=70:
print("grade a")
elif a>=50 and a<=60:
print("grade a")
else:
print("failed")
output:
enter the marks2
failed
# prompt: determine the day of a week
day = float(input("Enter a number between 1 and 7: "))
if day == 1:
print("Sunday")
elif day == 2:
print("Monday")
elif day == 3:
print("Tuesday")
elif day == 4:
print("Wednesday")
elif day == 5:
print("Thursday")
elif day == 6:
print("Friday")
elif day == 7:
print("Saturday")
else:
print("Invalid input. Please enter a number between 1 and 7.")
Enter a number between 1 and 7: 1
Sunday
# print the *
n=int(input("enter the n"))
i=1
while i<=n:
j=1
while j<=i:
print('*',end='')
j=j+1
print()
i=i+1
enter the n5
*
**
***
****
*****
# print the *
n=int(input("enter the n"))
i=5
while i>=1:
j=1
while j<=i:
print('*',end='')
j=j+1
print()
i=i-1
enter the n5
*****
****
***
**
*
# program to find the sum of first 10 natural numbers(while loop)
n=int(input("enter the value"))
sum=0
i=1
while i<=n:
sum=sum+i
i=i+1
print(sum)
enter the value10
55
# program to find the sum of first 10 natural numbers(for loop)
n=int(input("enter the value"))
sum=0
for i in range(1,n+1):
sum=sum+i
print(sum)
enter the value10
55
# write a program multiplication table (while loop)
n=int(input("enter the value"))
i=1
while i<=10:
print(n,"*",i,"=",n*i)
i=i+1
enter the value5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
# write a program multiplication table (for loop)
n=int(input("enter the value"))
for i in range(1,11):
print(n,"*",i,"=",n*i)
enter the value5
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
# write a program to print the each character of a string and string length
str=input("enter the string")
i=0
while i<len(str):
print(str[i])
i=i+1
print(len(str))
enter the stringcharan
c
h
a
r
a
n
6
# print the factorial of a number
i=1
f=1
n=int(input("enter the value"))
while i<=n:
f=f*i
i=i+1
print(f)
enter the value5
120
# write a program to check the whether the given number is prime or not
n=int(input("enter the value"))
i=2
while i<n:
if n%i==0:
print("not prime")
break
i=i+1
else:
print("prime")
enter the value7
prime
#programe to check the armstrong number or not
n=int(input("enter the number"))
sum=0
count=0
t=n
while t!=0:
t//=10
count =count+1
t=n
while n!=0:
r=n%10
sum=sum+r**count
n=n//10
if t==sum:
print(t,"is armstrong number")
else:
print(t,"is not a armstrong number")
enter the number153
153 is armstrong number