Skip to content

Commit 6aef3f9

Browse files
Add files via upload
1 parent c38495e commit 6aef3f9

27 files changed

+471
-0
lines changed

4_Raise error example 2.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Mobile:
2+
def __init__(self,name):
3+
self.name = name
4+
5+
class Mobilestore:
6+
def __init__(self):
7+
self.mobiles = []
8+
9+
def add_mobile(self,new_mobile):
10+
if isinstance(new_mobile,Mobile):
11+
self.mobiles.append(new_mobile)
12+
else:
13+
raise TypeError('New mobile should be object of mobile class')
14+
15+
oneplus = Mobile('One plus 6')
16+
samsung = 'Samsung galaxy M31'
17+
mobostore = Mobilestore()
18+
# print(mobostore.mobiles)
19+
20+
mobostore.add_mobile(oneplus)
21+
mobo_phones = mobostore.mobiles
22+
print(mobo_phones[0].name)

Chapter 18/1_Read text and files.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Methods ---> Read file , Open file , Read method , Seek method , Tell method , Read line , Read lines , Close method
2+
3+
# Read file
4+
5+
6+
# Open function
7+
8+
9+
# Read method
10+
# Ye method hamare cursor ki positon ko change krta hai
11+
12+
# Seek method
13+
# Ye method hamare file ko phir se read krta hai aur cursor ki position ko change bhi krta hai
14+
15+
# Tell method
16+
# Ye method hamare cursor k position ko batata hai
17+
18+
19+
# Readline method
20+
# Ye method hamare file k ek baar mein ek hi line read krta hai
21+
22+
# Readlines method
23+
# Ye method hamare file k sare line ko ek list me add kr dega aur hum jitni lines chahte hai utni lines ko read kr skte
24+
# hai iss method k use kr k.
25+
26+
# Close method
27+
28+
f = open('file.txt')
29+
# print(f'cursor position - {f.tell()}')
30+
#
31+
# print(f.read())
32+
# print(f'cursor position - {f.tell()}')
33+
# print('Before seek method :- ')
34+
# f.seek(0)
35+
# print('After seek method :- ')
36+
# print(f'cursor position - {f.tell()}')
37+
# print(f.read())
38+
# f.close()
39+
40+
41+
# Readline method
42+
43+
44+
# f = open('file.txt')
45+
#
46+
# print(f.readline())
47+
# print(f.readline())
48+
# print(f.readline())
49+
# print(f.readline())
50+
51+
52+
# Readlines method
53+
54+
# lines = f.readlines()
55+
# print(len(lines))
56+
# for line in lines:
57+
# print(line , end='')
58+
59+
# Close method
60+
print(f.closed)
61+
f.close()

Chapter 18/2_With blocks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
with open('file.txt') as f:
2+
data = f.read()
3+
print(data)
4+
5+
print(f.closed)

Chapter 18/3_write to file.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Aagr humko apne file k aandr kuch likhna hai toh uske liye hum ---> w , a , r+ ye theeno mode use kr skte hai.
2+
3+
# w mode ---> w mode k use tab kiya jata hai jab file empty hoti hai
4+
# with open('file1.txt','w') as f:
5+
# f.write('Hello ! Uttam sir how are welcom to my hotel sir.')
6+
7+
8+
# a mode ---> a mode tab use krte jab jab humko hamare file k data mein kuch add krna hota hai.
9+
# with open('file1.txt','a') as f:
10+
# f.write('\nHello ! Uttam sir how are welcom to my hotel sir.')
11+
12+
# r+ mode ---> r+ mode k use kr k hum apne file ko read bhi kr skte hai aur write bhi kr skte hai.
13+
with open('file1.txt','r+') as f:
14+
f.seek(len(f.read()))
15+
f.write('\nHello ! Uttam sir how are welcom to my hotel sir.')

Chapter 18/4_Read and write.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
with open('file2.txt', 'r') as rf:
2+
with open('file1.txt' , 'w') as wf:
3+
wf.write(rf.read())

Chapter 18/5_Exercise 1.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Uttam,500
2+
# Dinesh,50
3+
# Ankit,200
4+
# Anurag,100
5+
with open('salary.txt','r') as rf:
6+
with open('output.txt','a') as wf:
7+
for line in rf.readlines():
8+
name,salary = line.split(',')
9+
wf.write(f'{name}\'s salary is {salary} ')

Chapter 18/6_Exercise 2.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# with open('6_Exercise.html','r') as webpage:
2+
# with open('output1.txt','a') as wf:
3+
# for line in webpage.readlines():
4+
# if '<a href=' in line:
5+
# pos = line.find('<a href=')
6+
# first_quote = line.find('\"',pos)
7+
# second_quote = line.find('\"',first_quote+1)
8+
# url = line[first_quote+1:second_quote]
9+
# wf.write(url + '\n')
10+
11+
12+
# Better soluation to extract link in html files
13+
with open('6_Exercise.html','r') as webpage:
14+
with open('output.txt','a') as wf:
15+
page = webpage.read()
16+
link_exist = True
17+
while link_exist:
18+
pos = page.find('<a href=')
19+
if pos == -1:
20+
link_exist = False
21+
22+
else:
23+
first_quote = page.find('\"', pos)
24+
second_quote = page.find('\"',first_quote+1)
25+
url = page[first_quote+1:second_quote]
26+
wf.write(url + '\n')
27+
page = page[second_quote:]
28+

Chapter 18/6_Exercise.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<title>Page Title</title>
7+
<meta name="viewport" content="width=device-width,intial-scale=1">
8+
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
9+
<script src="main.js"><</script>
10+
</head>
11+
<body>
12+
<h1>hi there I'm Uttam Singh</h1>
13+
<a href="www.w3school.com">click to open w3school</a><a href="www.hackerearth.com">click here to open hackerank</a>
14+
<a href="www.Totrialspoint.com">click to open totrialspoint</a>
15+
<a href="www.geeksforgeeks">click to open geeksforgeeks</a>
16+
</body>
17+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
with open()

Chapter 18/Exercise 1 file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Uttam salary 500

Chapter 18/file.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This is a very important programming language for your software engineer career.
2+
3+
so workhard and give your best to complete your graduation and build your
4+
knowlege
5+
6+
Important things to remember.
7+
Never do somethig to impress someone.
8+
Never live your life on someone else opinions.
9+
Just find whatever you love and then hustle untill you don't need to introduce yourself.

Chapter 18/file1.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
i don't want to give my intro because i will make me better than every one.

Chapter 18/file2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
i don't want to give my intro because i will make me better than every one.

Chapter 18/file_2.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello ! Uttam sir how are welcom to my hotel sir.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from csv import DictReader, DictWriter
2+
with open('file.csv','r') as rf:
3+
with open('file1.csv','w') as wf:
4+
csv_reader = DictReader(rf)
5+
csv_writer = DictWriter(wf,fieldnames=['first_name','last_name','age'])
6+
csv_writer.writeheader()
7+
for row in csv_reader:
8+
fname, lname, age = row['firstname'],row['lastname'],row['age']
9+
csv_writer.writerow({
10+
'first_name': fname.upper(),
11+
'last_name': lname.upper(),
12+
'age' : age
13+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from csv import DictReader
2+
3+
# Ordered dict
4+
with open('file.csv','r') as f:
5+
csv_reader = DictReader(f)
6+
for row in csv_reader:
7+
print(row['name'])

Chapter 19/csv DictWriter.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import csv
2+
from csv import DictWriter
3+
4+
with open('final.csv','w',newline='') as f:
5+
csv_writer = DictWriter(f,fieldnames=['firstname','lastname','age'])
6+
7+
# writerow , writerows
8+
csv_writer.writerow({
9+
'firstname': 'Uttam',
10+
'lastname': 'Singh',
11+
'age':20
12+
})
13+
csv_writer.writerow({
14+
'firstname':'Shraddha',
15+
'lastname':'singh',
16+
'age':20
17+
})
18+
19+
# Writer -----> [dict , dict , dict]
20+
csv_writer.writerows([
21+
{'firstname':'Uttam','lastname':'Singh','age':20},
22+
{'firstname':'shraddha','lastname':'Singh', 'age':20}
23+
])

Chapter 19/csvwriter.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Writer , DictWriter
2+
from csv import writer
3+
4+
with open('file.csv1','w',newline='') as f:
5+
csv_writer = writer(f)
6+
7+
# methods --> writerow and writerows
8+
# csv_writer.writerow(['name','country'])
9+
# csv_writer.writerow(['Uttam','INDIA'])
10+
# csv_writer.writerow(['Shraddha','INDIA'])
11+
12+
13+
csv_writer.writerows([['Name','Country','Phone'],['Uttam','INDIA','9670064455'],['Shraddha','INDIA','8423854856']])

Chapter 19/file.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name,uttam,Phone
2+
email,uttampbh123@gmail.com,+91 9670064455
3+
contact,+91 7710843691,+91 9670064455

Chapter 19/file.csv1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Name,Countery,Phone
2+
Uttam,INDIA,9670064455
3+
Shraddha,INDIA,8423854856

Chapter 19/file1.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
first_name,last_name,age

Chapter 19/final.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Uttam,Singh,20
2+
Shraddha,singh,20
3+
Uttam,Singh,20
4+
shraddha,Singh,20

Chapter 19/readcsv.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from csv import reader
2+
3+
with open('file.csv', 'r') as f:
4+
csv_reader = reader(f)
5+
# iteration
6+
# print(csv_reader)
7+
# next(csv_reader)
8+
for row in csv_reader:
9+
print(row)

GUI Application/GUI Application.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# tee-kinter , Tk-inter , kinter
2+
3+
# Starter code
4+
import tkinter as tk
5+
from tkinter import ttk
6+
7+
8+
window = tk.Tk()
9+
window.title('GUI Application')
10+
11+
# Create labels
12+
name_label = ttk.Label(window, text='Enter the name :- ')
13+
name_label.grid(row=0, column=0, sticky=tk.W)
14+
15+
age_label = ttk.Label(window, text='Age :- ')
16+
age_label.grid(row=1, column=0, sticky=tk.W)
17+
18+
email_label = ttk.Label(window, text='Enter your email id:- ')
19+
email_label.grid(row=2, column=0, sticky=tk.W)
20+
21+
gender_label = ttk.Label(window, text='Select your gender:- ')
22+
gender_label.grid(row=3, column=0, sticky=tk.W)
23+
24+
# Creating entry box for each label
25+
name_variable = tk.StringVar()
26+
name_entrybox = ttk.Entry(window, width=16, textvariable=name_variable)
27+
name_entrybox.grid(row=0, column=1)
28+
name_entrybox.focus()
29+
30+
age_variable = tk.StringVar()
31+
age_entrybox = ttk.Entry(window, width=16, textvariable=age_variable)
32+
age_entrybox.grid(row=1, column=1)
33+
34+
email_variable = tk.StringVar()
35+
email_entrybox = ttk.Entry(window, width=16, textvariable=email_variable)
36+
email_entrybox.grid(row=2, column=1)
37+
38+
# gender_variable = tk.StringVar()
39+
# gender_entrybox = ttk.Entry(window,width=16,textvariable=gender_variable)
40+
# gender_entrybox.grid(row=3,column=1)
41+
42+
# Create combobox
43+
gender_variable = tk.StringVar()
44+
gender_combobox = ttk.Combobox(window, width=14, textvariable=gender_variable, state='readonly')
45+
gender_combobox['values'] = ('Male', 'Female', 'Transgender like Dinesh')
46+
gender_combobox.current(0)
47+
gender_combobox.grid(row=3, column=1)
48+
49+
# Creating radio button
50+
usertype = tk.StringVar()
51+
radio_button1 = ttk.Radiobutton(window, text='Student', value='Student', variable=usertype)
52+
radio_button1.grid(row=4, column=0)
53+
54+
radio_button2 = ttk.Radiobutton(window, text='Teacher', value='Teacher', variable=usertype)
55+
radio_button2.grid(row=4, column=1)
56+
57+
# Create check button
58+
59+
checkbutton = tk.IntVar()
60+
check_button = ttk.Checkbutton(window, text='Check if you want to subscribe our channel', variable=checkbutton)
61+
check_button.grid(row=5, columnspan=3)
62+
63+
# Create Button
64+
65+
def action():
66+
67+
username = name_variable.get()
68+
userage = age_variable.get()
69+
user_email = email_variable.get()
70+
71+
print(f'{username} is {userage} years old, {user_email}')
72+
73+
user_gender = gender_variable.get()
74+
user_type = usertype.get()
75+
if checkbutton.get() == 0:
76+
subscribed = 'No'
77+
else:
78+
subscribed = 'Yes'
79+
print(user_gender,user_type,subscribed)
80+
81+
with open('file.txt', 'a') as f:
82+
f.write(f'{username}{userage}{user_email}{user_gender}{usertype}{subscribed}\n')
83+
84+
name_entrybox.delete(0,tk.END)
85+
age_entrybox.delete(0,tk.END)
86+
email_entrybox.delete(0,tk.END)
87+
88+
name_label.configure(foreground='#b388ff')
89+
90+
submit_button.configure(foreground='Blue')
91+
92+
submit_button = tk.Button(window,text='Submit' , command=action)
93+
submit_button.grid(row=6,column=0)
94+
95+
96+
97+
98+
99+
'''Aagar hum mainloop() nhi likhenge toh hamara window turant chalu ho k bnd ho jayega iss liye hum mainloop k use kr
100+
rahe hai ki hamara window user bnd kre tb hi bnd ho......'''
101+
102+
window.mainloop()

0 commit comments

Comments
 (0)