Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a7dde21

Browse files
author
Rai Muhammad Haider
committed
Youtube Manager Project
1 parent 2401a0b commit a7dde21

File tree

4 files changed

+109
-6
lines changed

4 files changed

+109
-6
lines changed

‎ErrorHandling.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
x = ('mango', 'orange' , 'banana')
2+
y = enumerate(x)
3+
print(y)
4+
print(list(y))
5+
# this is our first method
6+
# myFile = open('myfile.py', 'w')
7+
# with open('myfile.py','w') as myfile:
8+
# myfile.write('this is my file')
9+
with open('Second.py','w') as secnod: # it will create or open a file that we fill in it enter the name of the file
10+
secnod.write('hey! i am Second File') # it will make changes of the file
11+
# and this one is our second method
12+
apniFile = open('Apni.py','w')
13+
try:
14+
apniFile.write('ya to ha apni file')
15+
finally:
16+
apniFile.close()

‎Functions.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Function with default parameter
22
def default_parameter(city='Lahore'):
3-
print(city, 'is Your city')
3+
print(f"the name of City is : {city}")
44

55
default_parameter('Okara')
66

77

88
# Function with unknown number of positional arguments (*args)
99
def unknown_parameters(*name):
10-
print('The name of the winner is', name[1])
10+
print(f"The name of the winner is'{name[1]}")
1111

1212
unknown_parameters('Ali', 'Haider', 'Hafiz')
1313

@@ -24,12 +24,19 @@ def my_function(child3, child2, child1):
2424
'name': 'Ali',
2525
'age': 21,
2626
}
27+
def passingDictionaryTOfunction(anyDictionary):
28+
for key in anyDictionary:
29+
print(key , anyDictionary[key])
2730

28-
def passing_dict(info):
29-
for key in info:
30-
print(key, ':', info[key])
31+
print(passingDictionaryTOfunction(students))
3132

32-
passing_dict(students)
33+
34+
35+
# def passing_dict(info):
36+
# for key in info:
37+
# print(key, ':', info[key])
38+
39+
# passing_dict(students)
3340

3441

3542
# Basic function returning square

‎YoutubeManager.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import json # learn about json
2+
3+
def load_data():
4+
try:
5+
with open('youtube.txt' , 'r') as file :
6+
return json.load(file) # it wil go to file and load the data and also convert the data into json
7+
except FileNotFoundError:
8+
return []
9+
10+
def save_data_helper(videos):
11+
with open('youtube.txt' , 'w') as file:
12+
json.dump(videos , file) # what to store and where to store
13+
14+
def list_all_videos(videos):
15+
print('\n')
16+
print('*' * 70)
17+
for index , video in enumerate(videos , start=1): #enumerate basically provide indexing we cal also start indexing from a certain piint
18+
print(f"{index}. {video['name']} Duration : {video['time']}")
19+
print('\n')
20+
print('*' * 70)
21+
22+
23+
def add_videos(videos):
24+
name = input('Enter video name: ')
25+
time = input('Enter video time: ')
26+
videos.append({'name' : name , 'time' : time})
27+
save_data_helper(videos)
28+
29+
def update_videos(videos):
30+
list_all_videos(videos)
31+
index = int(input('Enter the video number to delete: '))
32+
if 1 <= index <= len(videos):
33+
name = input('Enter the name of the video: ')
34+
time = input('Enter the Duration of the video: ')
35+
videos[index-1] = {'name': name , 'time':time}
36+
save_data_helper(videos)
37+
else:
38+
print('Invalid index selected')
39+
40+
41+
def delete_videos(videos):
42+
list_all_videos(videos)
43+
index = int(input('Enter the video number to be deleted'))
44+
if 1 <= index <= len(videos):
45+
del videos[index-1]
46+
save_data_helper(videos)
47+
else:
48+
print('Invalid video index selected')
49+
50+
51+
52+
def main():
53+
videos = load_data()
54+
while True:
55+
print('\n Youtube Manager | choose an option')
56+
print('1. List all Youtube videos')
57+
print('2. add a Youtube video')
58+
print('3. Update a Youtube video')
59+
print('4. Delete a Youtube video')
60+
print('5. Exit the app')
61+
chose = input('Enter Your choice: ')
62+
print(videos)
63+
64+
match chose:
65+
case '1':
66+
list_all_videos(videos)
67+
case '2':
68+
add_videos(videos)
69+
case '3':
70+
update_videos(videos)
71+
case '4':
72+
delete_videos(videos)
73+
case '5':
74+
break
75+
case _:
76+
print('Invalid Choice')
77+
78+
if __name__ == '__main__':
79+
main()

‎youtube.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"name": "3", "time": "100"}, {"name": "new car vlog", "time": "10 mintus"}, {"name": "Khan Move", "time": "2 hours"}]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /