Skip to content

Commit c5dfc22

Browse files
committed
Day8 added
1 parent a4afdc9 commit c5dfc22

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

Day8/audiobook.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pyttsx3 as ts #import python text to speech module
2+
import PyPDF2 as pdf #import pythn pdf reader module
3+
import os
4+
5+
path = os.path.join("Desktop","Books","Do the Work.pdf")
6+
7+
open_pdf=open(path,'rb')
8+
9+
read_pdf=pdf.PdfFileReader(open_pdf)
10+
11+
#speak from page asssigned
12+
speak=ts.init()
13+
speak.setProperty("rate", 178)
14+
#read first 10 pages
15+
for start_read in range(10):
16+
starting_page=read_pdf.getPage(start_read)
17+
text=starting_page.extractText()
18+
speak.say(text)
19+
speak.runAndWait()

Day8/password-validator.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import string
2+
import time
3+
4+
def login():
5+
username=input('Enter your name:')
6+
password=input('Enter the password:')
7+
return password
8+
9+
def passdetails():
10+
print('*'*35)
11+
print('The password must contain total of 14 charachters')
12+
print('It must contain one upper case with total of minimum 8 letters')
13+
print('it must contain 2 numbers')
14+
print('It must contain atleast one special character')
15+
print('*'*35)
16+
17+
def passtype(pword):
18+
lower=string.ascii_lowercase
19+
upper=string.ascii_uppercase
20+
number=string.digits
21+
symbol=string.punctuation
22+
lower_count=upper_count=number_count=symbol_count=0
23+
for letter in pword:
24+
if letter in lower:
25+
lower_count+=1
26+
if letter in upper:
27+
upper_count+=1
28+
if letter in number:
29+
number_count+=1
30+
if letter in symbol:
31+
symbol_count+=1
32+
if(lower_count>=7 and upper_count>=1 and number_count>=2 and symbol_count>=1):
33+
return('Strong')
34+
else:
35+
return('Weak')
36+
37+
passdetails()
38+
time.sleep(5)
39+
password=login()
40+
print(passtype(password))

Day8/sort_dict_value

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
manual = {"apple":12,"mango":23,"cake":2,"pastries":4,"chocolate":56}
2+
sorted_dict = dict(sorted(manual.items(),reverse=True,key=lambda x:x[1]))
3+
print(sorted_dict)
4+
"""
5+
sorted returns in list with a tuple of dictionary items with values at index one
6+
"""
7+
8+

Day8/try_and_except_examples.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Suppose you want your program to run error free, well everyone wants that.
3+
But what if we need our program to run even if there is an error, is there any possibility? Yes There sure is.
4+
Python provides Try and except, using this you can show user the message when certain error is occurred we call it exception.
5+
User get the feedback where he went wrong, using Try And Except Technique.
6+
Giving feedback for your program is every important.
7+
I hope even I do get some feedback about this 30DaysOfPython, I will be waiting for your feedback.
8+
Back to Try and Except again, here you will require the knowledge of some common errors
9+
"""
10+
#example 1
11+
12+
try:
13+
a = int(input("Enter a number: ")) #integer inputs required
14+
b = int(input("Enter a number2: "))
15+
div = a/b
16+
if a>b:
17+
print("{} is greater than {}. Quotient is:{}".format(a,b,div))
18+
else:
19+
print("{} is greater than {}. Quotient is:{}".format(b,a,div))
20+
21+
except ValueError as e:
22+
#this except block is printed when user enters a string instead of integer
23+
print("This Occured:",e)
24+
except ZeroDivisionError as e:
25+
#this except block is printed when user inputs 0 to number 2, b
26+
print("This occured:",e)
27+
28+
#example 2
29+
try:
30+
ceo = {"Google":"Sundar Pichai",
31+
"Microsoft":"Satya Nadella",
32+
"Adobe":"Shantanu Narayen",
33+
"Tesla":"Elon Musk",
34+
"Apple":"Tim Cook",
35+
"Facebook":"Mark Zuckerberg"}
36+
37+
ceo['Amazon'] = "Andy Jassy"
38+
39+
print(ceo["PayTM"])
40+
print(ceo["Google"])
41+
print(ceo["Tesla"])
42+
print(ceo["Amazon"])
43+
print(ceo["Apple"])
44+
45+
except KeyError as k:
46+
#this except block is executed when invalid key is entered
47+
print("This key is not found in the dictionary",k)
48+
except Exception as e:
49+
print("Something went wrong",e)
50+
51+
#example 3
52+
53+
try:
54+
with open("unknownfile.txt") as file:
55+
content = file.read()
56+
print(content)
57+
except FileNotFoundError:
58+
print("Oops! No File Found, Check Folder of the file and Try Again:)")

0 commit comments

Comments
 (0)