Skip to content

Commit 3eb85c9

Browse files
Add files via upload
1 parent 7614c86 commit 3eb85c9

26 files changed

+435
-0
lines changed

average.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
no_list = [10, 20, 30, 40]
2+
3+
def average(x):
4+
sum = 0
5+
for num in x:
6+
sum += num
7+
return sum / len(x)
8+
9+
print(average(no_list))

breakify.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def breakify(strings):
2+
return "<br>".join(strings)
3+
4+
lines = ["Haiku frogs in snow",
5+
"A limerick came from Nantucket",
6+
"Tetrametric drum-beats thrumming, Hiawathianic rhythm."]
7+
print(breakify(lines))

concatenation.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def adverbly(s):
2+
return s + 'ly'
3+
4+
print(adverbly("quick"))

count_chrSub.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def count_character(string, target):
2+
index = 0
3+
total = 0
4+
while index < len(string):
5+
if string[index] == target:
6+
total += 1
7+
index += 1
8+
print(total)
9+
count_character("papa pony and the parcel post problem", "p")
10+
11+
def count_substring(string, sub):
12+
total = 0
13+
index = 0
14+
while index < len(string):
15+
if string[index : index + len(sub)] == sub:
16+
total += 1
17+
index += len(sub)
18+
else:
19+
index += 1
20+
print(total)
21+
22+
count_substring('love, love, love, all you need is love', 'love')
23+
count_substring('AAAA', 'AA')

countdown.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import time
2+
n = 10
3+
while n > 0:
4+
print(n)
5+
n -= 1
6+
time.sleep(1)
7+
8+
print("Blastoff!")

demo.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
n1 = input("Enter a First number: ")
2+
n2 = input("Enter a Second number: ")
3+
n3 = input("Enter a Third number: ")
4+
sum = int(n1) + int(n2) + int(n3)
5+
print(f"{n1} + {n2} + {n3} = {sum}")
6+
dif = int(n1) - int(n2) - int(n3)
7+
print(n1 + ' - ' + n2 + ' - ' + n3 + ' = ' + str(dif))

downTube.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import tkinter as tk
2+
from tkinter import *
3+
from pytube import *
4+
from tkinter import messagebox
5+
6+
# from pytube import YouTube
7+
# from pytube import streams
8+
# from pytube.streams import Stream
9+
10+
root = tk.Tk()
11+
root.title('Youtube Downloader')
12+
root.geometry('500x200')
13+
14+
link_var = StringVar()
15+
link = link_var.get()
16+
17+
ytb = YouTube
18+
19+
# video = ytb(link)
20+
21+
22+
def url():
23+
link = link_var.get()
24+
yt = ytb(link)
25+
# filter(progressive=True, res=" 1080p", subtype='mp4')
26+
stream = yt.streams.get_highest_resolution()
27+
stream.download('C:/Users/abdel/Videos/Youtube')
28+
link_var.set("")
29+
messagebox.showinfo(title='Download', message='Done')
30+
31+
32+
def info():
33+
video = ytb(link)
34+
35+
print(f"Title: \n {video.title} \n ")
36+
print(f"Description: \n {video.description} \n")
37+
print(f"Views: \n {video.views} watchers \n ")
38+
print(f"Rating: \n {video.rating} / 5 \n ")
39+
print(f"Duration \n{video.length/60} minutes \n ")
40+
41+
42+
title = Label(root, text='Youtube Downloader',
43+
font=('Helvatical bold', 30, 'bold')).pack()
44+
45+
ent = Entry(root, width="50", textvariable=link_var).pack()
46+
47+
info = Button(root, text='Get Info', command=info).pack()
48+
49+
down = Button(root, text='Download', command=url).pack()
50+
51+
l = Label(root, text='By ABDELILAH').pack(side=BOTTOM)
52+
53+
root.mainloop()
54+
55+
56+
def finish():
57+
print("Download Done")
58+
59+
60+
video.register_on_complete_callback(finish())

find_num.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def find_512(x, y):
2+
for x in range(100):
3+
for y in range(100):
4+
if x * y == 512:
5+
return f"{x} * {y} == 512"
6+
print(f"{x} * {y} == 512")
7+
8+
x = 0
9+
y = 0
10+
find_512(x, y)

helloWorld.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import tkinter
2+
from tkinter import *
3+
4+
tk = Tk()
5+
tk.title('First App')
6+
tk.geometry('250x100')
7+
8+
9+
frame = Frame(tk, relief=SUNKEN, borderwidth=2, bd=2, bg="white",
10+
highlightbackground="blue", highlightthickness=2)
11+
frame.pack(fill=BOTH, expand=1)
12+
13+
var = StringVar()
14+
var.set("Hello World")
15+
16+
label = Label(frame, textvariable=var, fg="red",
17+
bg="yellow", cursor="dot", relief=RAISED, underline=5, wraplength=50)
18+
label.pack(expand=1)
19+
20+
button = Button(frame, text="Exit", command=tk.destroy,
21+
padx=10, pady=3, bg="skyblue", activebackground="blue")
22+
button.pack(side=BOTTOM)
23+
24+
tk.mainloop()

locate_first.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def locate_first(string, sub):
2+
index = 0
3+
while index < len(string):
4+
if string[index : index + len(sub)] == sub:
5+
return index
6+
else:
7+
index += 1
8+
return -1
9+
10+
print(locate_first('cookbook', 'ook'))
11+
print(locate_first('all your bass are belong to us', 'base'))
12+
13+
def locate_all(string, sub):
14+
matches = []
15+
index = 0
16+
while index < len(string):
17+
if string[index : index + len(sub)] == sub:
18+
matches.append(index)
19+
index += len(sub)
20+
else:
21+
index += 1
22+
print(matches)
23+
locate_all('cookbook', 'ook')

maximum.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
no_list = [5,20,12,6]
2+
3+
def maximum(no_list):
4+
max = 0
5+
for num in no_list:
6+
if max < num:
7+
max = num
8+
return max
9+
print(maximum(no_list))

methods.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
words = ["echidna", "dingo", "crocodile", "bunyip"]
2+
words.append("platypus")
3+
words.extend("abc")
4+
words.extend(["kangaroo", "wallaby"])
5+
print(words)
6+
words.reverse()
7+
print(words)
8+
words.sort()
9+
print(words)
10+
11+
first_list = [1, 2, 3]
12+
second_list = [4, 5, 6]
13+
for item in second_list:
14+
first_list.append(item)
15+
first_list.extend([7, 8, 9])
16+
print(first_list)

no_repeating.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def no_repeating():
2+
words = []
3+
while True:
4+
word = input("Tell me a word: ")
5+
if word in words:
6+
print("You told me that word already!")
7+
break
8+
words.append(word)
9+
return words
10+

password.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def password_check(password, code):
2+
while len(password) >= 8 and len(password) < 64:
3+
print("Good Length")
4+
code = input("Password Check: ")
5+
while code != password:
6+
code = input('Please check the password: ')
7+
print("Password Checked")
8+
print ("Password need more caracteres")
9+
10+
print("Password: ")
11+
password = input()
12+
code = ""
13+
password_check(password, code)

playlist_downloader.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pytube import YouTube
2+
from pytube import Playlist
3+
from pytube import streams
4+
5+
6+
playlist_link = input('Enter playlist link : ')
7+
8+
playlist = Playlist(playlist_link)
9+
10+
for video in playlist:
11+
link = YouTube(video)
12+
link.streams.get_highest_resolution().download(
13+
"C:/Users/abdel/Videos/Youtube/Playlist")
14+
15+
def finish():
16+
print("Download Done")
17+
18+
playlist.register_on_complete_callback(finish())

reverse_text.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
text = ""
2+
def reverse(x):
3+
x = []
4+
x.extend(text)
5+
x.reverse()
6+
return ''.join(x)
7+
print("the reversed text is: " + reverse(text))

silly_string.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import random
2+
3+
def silly_string(nouns, verbs, templates):
4+
# Choose a random template.
5+
template = random.choice(templates)
6+
# We'll append strings into this list for output.
7+
output = []
8+
# Keep track of where in the template string we are.
9+
index = 0
10+
11+
while index < len(template):
12+
if template[index:index+8] == '{{noun}}':
13+
# Add a random noun to the output.
14+
output.append(random.choice(nouns))
15+
index += 8
16+
elif template[index:index+8] == '{{verb}}':
17+
# Add a random verb to the output.
18+
output.append(random.choice(verbs))
19+
index += 8
20+
else:
21+
# Copy a character to the output.
22+
output.append(template[index])
23+
index += 1
24+
# Join the output into a single string.
25+
return ''.join(output)
26+
nouns = ['apple', 'ball', 'cat', 'dog', 'elephant',
27+
'fish', 'goat', 'house', 'iceberg', 'jackal',
28+
'king', 'llama', 'monkey', 'nurse', 'octopus',
29+
'pie', 'queen', 'robot', 'snake', 'tofu',
30+
'unicorn', 'vampire', 'wumpus', 'x-ray', 'yak',
31+
'zebra']
32+
33+
verbs = ['ate', 'bit', 'caught', 'dropped', 'explained',
34+
'fed', 'grabbed', 'hacked', 'inked', 'jumped',
35+
'knitted', 'loved', 'made', 'nosed', 'oiled',
36+
'puffed', 'quit', 'rushed', 'stung', 'trapped',
37+
'uplifted', 'valued', 'wanted']
38+
39+
templates = ['Waiter! I found a {{noun}} in my {{noun}}!',
40+
'The {{noun}} {{verb}} the {{noun}}.',
41+
'If you {{verb}} the {{noun}}, '
42+
'the {{noun}} will get you.',
43+
"Let's go: the {{noun}} is {{verb}}.",
44+
'Colorless green {{noun}}s {{verb}} furiously.']
45+
46+
if __name__ == '__main__':
47+
print(silly_string(nouns, verbs, templates))
48+

startWith.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def start_A(s):
2+
return s.startswith("A")
3+
4+
def start_K(s):
5+
if s[0] == "K":
6+
return True
7+
else:
8+
return False
9+
10+
print(start_K("Kelly"))
11+
print(start_K("Abe"))
12+
13+
word = input("Possible tag: ")
14+
def possible_tag(word):
15+
if word.startswith("<") and word.endswith(">"):
16+
print(word, "could maybe be an HTML tag")
17+
else:
18+
print(word, """is definitely not an HTML tag\
19+
(but might contain one)""")
20+
possible_tag(word)

substring.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def is_substring(substring, string):
2+
index = 0
3+
while index < len(string):
4+
if string[index : index + len(substring)] == substring:
5+
print("True")
6+
index += 1
7+
print("False")
8+
9+
string = 'waffles'
10+
substring = 'ff'
11+
is_substring(substring, string)

0 commit comments

Comments
 (0)