Skip to content

Instantly share code, notes, and snippets.

View cristinelpopescu's full-sized avatar

Cristinel-Adrian Popescu (Cristian) cristinelpopescu

View GitHub Profile
# 10_basic.py
# 15_make_soup.py
# 20_search.py
# 25_navigation.py
# 30_edit.py
# 40_encoding.py
# 50_parse_only_part.py
# Password checker
# At least 8 characters long
# Contain any sort of letters, numbers, @%$#
# Has to end with a number
import re
pattern = re.compile(r"([a-zA-Z]).([a])")
string = 'search inside of this text'
# fibonacci - generator
def fib(number):
a = 0
b = 1
for i in range(number):
yield a
temp = a
a = b
b = temp + b
for x in fib(20):
# fibonacci - generator
def fib(number):
a = 0
b = 1
for i in range(number):
yield a
temp = a
a = b
b = temp + b
for x in fib(20):
# decorator
from time import time
def performance(fn):
def wrapper (*args, **kawrgs):
t1 = time()
result = fn(*args, **kawrgs)
t2 = time()
print(f'took {t2 - t1} s')
return result
new_sentence = "!".join(["Ana", "are", "mere"])
print(new_sentence)
# alternative:
# space = "!"
# new_sentence = space.join(["Ana", "are", "mere"])
# print(new_sentence)
@cristinelpopescu
cristinelpopescu / average.py
Created March 8, 2021 13:38
this program calculates average of three numbers
#average of three numbers
x = input("enter first number: ")
y = input("enter the second number: ")
z= input("enter the third number: ")
average = (float(x) + float(y) + float(z)) / float(3)
print("your average is: ", average )
def fibonacci():
num = int(input("How many numbers you want to generate?: "))
i = 1
if num == 0:
fib = []
elif num == 1:
fib = [1]
elif num == 2:
fib = [1,1]
elif num > 2:
@cristinelpopescu
cristinelpopescu / palindrome.py
Created February 28, 2021 16:10
Ask the user for a string and print out whether this string is a palindrome or not. A palindrome is a string that reads the same forwards and backwards.
phrase=input("Please enter a phrase or word: ")
phrase=str(phrase)
reverse= phrase[::-1]
print(reverse)
if phrase == reverse:
print("This phrase or word is a palindrome")
else:
print("This phrase or word is not a palindrome")
@cristinelpopescu
cristinelpopescu / password_generator.py
Created February 28, 2021 16:03
Advanced password generator
import string
import random
def pw_gen(size = 8, chars=string.ascii_letters + string.digits + string.punctuation):
return ''.join(random.choice(chars) for _ in range(size))
print(pw_gen(int(input('How many characters in your password? (enter an integer value) '))))