-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathayushi.py
371 lines (307 loc) · 7.6 KB
/
ayushi.py
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
# -*- coding: utf-8 -*-
"""Untitled0.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1hUUk5AUHJZqJ7lwqW4EWbXMBK_9f750Z
"""
# 1.Prime or not
n=int(input())
c=0
d=0
for i in range(1,n+1):
if(n%i==0):
c=c+1
else:
d=d+1
if(c==2):
print("Prime")
else:
print("Not Prime")
# 2. Replace vowel with *
n=input()
n1=""
for char in n:
if char.lower() in 'aeiou':
n1+='*'
else:
n1+=char
print(n1)
# 3. Check Palindrome
n=input()
n1=n.lower()
n2=n1[::-1]
if(n1==n2):
print("palindrome")
else:
print("not palindrome")
# 4. Largest and smallest in list
n=input().split()
l=max(n)
s=min(n)
print(l)
print(s)
#4.largest and Smallest in tuple
t = tuple(map(int,input().split()))
l=max(t)
s=min(t)
print(l)
print(s)
# 5.# Dictionary to store student records
student_records = {
1: {"admission_number": 101, "roll_number": "45", "name": "John", "percentage": 85.5},
2: {"admission_number": 102, "roll_number": "68", "name": "Rohan", "percentage": 92.3},
3: {"admission_number": 103, "roll_number": "72", "name": "Ayush", "percentage": 95.3},
4: {"admission_number": 104, "roll_number": "78", "name": "Prachi", "percentage": 89.3},
}
n= int(input())
student = student_records.get(n)
if student:
print("Student Details:")
print("Admission Number:", student.get("admission_number"))
print("Roll Number:", student.get("roll_number"))
print("Name:", student.get("name"))
print("Percentage:", student.get("percentage"))
else:
print("Student with admission number",n, "not found.")
#6.square of a no.
n=int(input())
print(n*n)
# 6.log
import math
n=int(input())
result = math.log(n)
print(result)
#6.quad of a no.
n=int(input())
m= n**2
print(m)
#7.menu driven airthmetic operations
n=int(input())
n1=int(input())
print("Press 1 for Addition")
print("Press 2 for Subtraction")
print("Press 3 for Multiplication")
print("Press 4 for Divison")
choice=int(input())
if(choice==1):
print(n+n1)
elif(choice==2):
print(n-n1)
elif(choice==3):
print(n*n1)
elif(choice==4):
print(n/n1)
else:
print("Not a right choice")
#8.fibo
n=int(input())
a=0
b=1
count=0
if n<=0:
print("not applicable")
elif n==1:
print(a)
else:
while count<n:
print(a, end=" ")
c=a+b
a=b
b=c
count=count+1
#9.
def fact(n):
if n == 0 or n == 1:
return 1
else:
return n * fact(n - 1)
def list_sum(numbers):
return sum(numbers)
print("Enter 1 for factorial")
print("Enter 2 for sum for list elements")
choice=int(input())
if(choice==1):
n=int(input())
print(fact(n))
elif(choice==2):
a=list(map(int,input().split()))
print(list_sum(a))
else:
print("wrong choice")
#10.
l=[2,1,3,4,5,6,7]
sum=0
for i in l:
if i%2==0:
sum+=(i*10)
print(sum)
#11.
l=["hiiiii","helloo","jaya","JAYA","RAM","END","AYUHEA"]
for i in l:
if(i[-1]=="A"):
print(i)
#12.read a text file line by line and display each word separated by #
file = open("python.txt", "r")
for line in file:
words = line.split()
new_line = '#'.join(words)
print(new_line)
file.close()
#13 read a text file and display number of vowels
total_vowels = 0
total_constants = 0
total_uppercase = 0
total_lowercase = 0
file = open("python.txt", "r")
for line in file:
words = line.split()
for word in words:
vowels = sum(1 for char in word if char.lower() in ['a', 'e', 'i', 'o', 'u'])
uppercase = sum(1 for char in word if char.isupper())
lowercase = sum(1 for char in word if char.islower())
constants = sum(1 for char in word if not char.isalpha())
total_vowels += vowels
total_constants += constants
total_uppercase += uppercase
total_lowercase += lowercase
file.close()
print("Number of vowels: ", total_vowels)
print("Number of constants: ", total_constants)
print("Number of uppercase letters: ", total_uppercase)
print("Number of lowercase letters: ", total_lowercase)
#14 remove all the lines that contains the character 'a' in a file and write it to another file and show all copied data
with open("python.txt", "r") as file:
lines = file.readlines()
with open("newfile.txt", "w") as newfile:
for line in lines:
if 'a' not in line:
newfile.write(line)
with open("newfile.txt", "r") as newfile:
lines = newfile.readlines()
for line in lines:
print(line.strip())
#15. WAP to count the words "to" and "the" present in the file
count = {'to': 0, 'the': 0}
words = ['to', 'the']
with open("python.txt", "r") as file:
lines = file.readlines()
for line in lines:
words1 = line.lower().split()
for word in words:
count[word] += words1.count(word)
print(f"to appears {count['to']} times.")
print(f"the appears {count['the']} times.")
#16.
#17 WAP to count occurence of each word in a given file
file_name = 'python.txt'
count = {}
with open(file_name, 'r') as file:
words = file.read().split()
for word in words:
word = word.lower()
if word in count:
count[word] += 1
else:
count[word] = 1
print(count)
#18.WAP to count number of words in a given file
file_name = 'python.txt'
with open(file_name, 'r') as file:
words = file.read().split()
count = len(words)
print(f'total no. of words are: {count}')
#24 random no. generator
import random
result = random.randint(1,6)
result
#PDF QUESTION
#1 WAP to convert long seconds in hour....
n=int(input())
hours=n//3600
minutes=(n//60)%60
seconds=n%60
print("{} Hours {} Minutes {} Seconds".format(hours,minutes,seconds))
#2 "Autulya".....
str=input()
print(str[0:1])
print(str[1:3])
print(str[3:])
#3
#4 domination of a no....
amount = int(input())
denominations = [2000, 500, 200, 100, 50, 10, 5, 2, 1]
for denom in denominations:
count = 0
while amount >= denom:
count += 1
amount -= denom
if count != 0:
print(denom, "-", count)
#5 functions of list
l=input("enter the list:elements seprated by ,").split(',')
print("Display list:",l)
l.sort()
print("sort the list:",l)
l.append("new")
print("add element to the list:",l)
l.remove("new")
print("delete an element from the list",l)
print("length of list",len(l))
l.clear()
print("clear the list:",l)
#6 character is alphabet digit....
ch=(input())
if(ch.isalpha()):
print("It is an Alphabet")
elif(ch.isdigit()):
print("It is a Digit")
else:
print("It is a Special Character")
#7 create dictinary...
keys = [10, 20, 30]
values = ['Ten', 'Twenty', 'Thirty']
res_dict = dict(zip(keys, values))
print(res_dict)
#8
#9 random no. generator...
import random
r = random.randint(1,6)
print(r)
#10 calculate electricity bill
def Functionbill(units):
surcharge = 0
if units <= 50:
amt = units * 2.60
surcharge = 25
elif units <= 100:
amt = 130 + ((units - 50) * 3.25)
surcharge = 35
elif units <= 200:
amt = 130 + 162.50 + ((units - 100) * 5.25)
surcharge = 45
else:
amt = 130 + 162.50 + 526 + ((units - 200) * 8.45)
surcharge = 75
final_bill = amt + surcharge
return final_bill
units_consumed = int(input("Enter the units consumed: "))
bill_amount = Functionbill(units_consumed)
bill_amount
#11 strong password
def check(password):
if len(password) < 8:
return False
if not any(char.isupper() for char in password):
return False
if '_' not in password:
return False
if not any(char.isdigit() for char in password):
return False
return True
def main():
user_password = input("Enter your password: ")
if check(user_password):
print("Password is strong.")
else:
print("Password is not strong.")
main()