This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A = float(input('enter a number ')) | |
if (A % 2) == 0: | |
print('number is even') | |
else: | |
print('number is odd') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#some simple math | |
A = float(input('enter A number: ')) | |
B = float(input('enter B number: ')) | |
#addition | |
#print( A + B) | |
#substraction | |
#print( A - B) | |
#divide |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) ')))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new_sentence = "!".join(["Ana", "are", "mere"]) | |
print(new_sentence) | |
# alternative: | |
# space = "!" | |
# new_sentence = space.join(["Ana", "are", "mere"]) | |
# print(new_sentence) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
OlderNewer