Skip to content

Instantly share code, notes, and snippets.

View cristinelpopescu's full-sized avatar

Cristinel-Adrian Popescu (Cristian) cristinelpopescu

View GitHub Profile
A = float(input('enter a number '))
if (A % 2) == 0:
print('number is even')
else:
print('number is odd')
#some simple math
A = float(input('enter A number: '))
B = float(input('enter B number: '))
#addition
#print( A + B)
#substraction
#print( A - B)
#divide
@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) '))))
@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")
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 / 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 )
new_sentence = "!".join(["Ana", "are", "mere"])
print(new_sentence)
# alternative:
# space = "!"
# new_sentence = space.join(["Ana", "are", "mere"])
# print(new_sentence)
# 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
# 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):