Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions greatest_cmmn_dvsr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### As a user, I want to use a program which can calculate the greatest common divisor (GCD) of my inputs.

class FormulaError(Exception):
pass
import math

def entry(x,y): # I tried to use 'Exceptions
try:
x = str or float
except ValueError as ne:
raise FormulaError(ne)
else:
y = str
raise FormulaError("Please entry a number!")

x = int(input("Please entry a num for x: "))
y = int(input("Please entry a num for y: "))
def gcd(x,y):
return math.gcd(x,y)
print(gcd(x,y))
#print(entry(x,y))
51 changes: 51 additions & 0 deletions hackerrank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
### Diagonal Difference

def difference(arr, n):
d1 = 0
d2 = 0

for i in range(0, n):
d1 += arr[i][i]
d2 += arr[i][n - i - 1]
return abs(d1 - d2)
n = 3
arr = [[11, 2, 4],
[4 , 5, 6],
[10, 8, -12]]
print("Diagonal Difference", difference(arr, n))

### Left Rotation

def leftrotate(arr,n,d):
tem = []
i = 0
while (i < d):
tem.append(arr[i])
i += 1
i = 0
while (d < n):
arr[i] = arr[d]
i += 1
d += 1
arr[:] = arr[: i] + tem
return arr
arr = [0,7,1,9,0,7,1,9]
print("Left Rotation", leftrotate(arr, len(arr), 2))

### Counter Game

def counterGame(n):
n = bin(n)[2:]
n = n.split('1')
turns = len(n)+len(n[-1])-2
return 'Louise' if turns&1 else 'Richard'
print(counterGame(132))

### Time Delta
from datetime import datetime

time_format = "%a %d %b %Y %H:%M:%S %z"
for i in range(int(input("Please entry comparison places: "))):
time1 = datetime.strptime(input("Please entry this date, time and zone: "), time_format )
time2 = datetime.strptime(input("Please entry this date, time and zone: "), time_format )
print(int(abs((time1 - time2).total_seconds())))
Empty file added my_dice.py/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions my_dice.py/basic_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import dice_percentage

while True :
print("Please press Q for exit")
repetition = input("repetition : ")
if repetition == "Q" or repetition == "p":
break
else :
repetition = int(repetition)
print(f"percentage of throws of value 1 = {dice_percentage.percentage(1,repetition):.2f} %")
print(f"percentage of throws of value 2 = {dice_percentage.percentage(2,repetition):.2f} %")
print(f"percentage of throws of value 3 = {dice_percentage.percentage(3,repetition):.2f} %")
print(f"percentage of throws of value 4 = {dice_percentage.percentage(4,repetition):.2f} %")
print(f"percentage of throws of value 5 = {dice_percentage.percentage(5,repetition):.2f} %")
print(f"percentage of throws of value 6 = {dice_percentage.percentage(6,repetition):.2f} %")
33 changes: 33 additions & 0 deletions my_dice.py/dice_percentage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### Create an array with 6 elements named dice. Fill this array with the value zero.
### Generate a random number with a value between 1 and 6 (just like a dice) in a repetition 5000 times.



import numpy as np # I used some 'Modelus'

def dice_perc(x):
np.random.seed(1907)
dice = np.array([1,2,3,4,5,6])
dice_1 = []
for i in range(int(5000)):
turn = np.random.choice(dice)
dice_1.append(int(turn))
d1c = dice_1.count(1)
d2c = dice_1.count(2)
d3c = dice_1.count(3)
d4c = dice_1.count(4)
d5c = dice_1.count(5)
d6c = dice_1.count(6)
per_1 = d1c/5000
per_2 = d2c/5000
per_3 = d3c/5000
per_4 = d4c/5000
per_5 = d5c/5000
per_6 = d6c/5000

percentage = ("Percentage of throws of value 1: {:.2%}\nPercentage of throws of value 2: {:.2%}\n"
"Percentage of throws of value 3: {:.2%}\nPercentage of throws of value 4: {:.2%}\n"
"Percentage of throws of value 5: {:.2%}\nPercentage of throws of value 6: {:.2%}"
.format(per_1,per_2,per_3,per_4,per_5,per_6))
return percentage
print(dice_perc(5000))
30 changes: 30 additions & 0 deletions password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Write a Python program to check the validity of a password (input from users)
### Rules :
### At least 1 letter between [a-z] and 1 letter between [A-Z]
### At least 1 number between [0-9].
### At least 1 character from [$#@].
### Minimum length 6 characters.
### Maximum length 16 characters.

class FormulaError(Exception):
pass
import string # I tried to use some 'Modelus'
import stdiomask

def password(passwordd): # I tried to use 'Exceptions'
lengt = len(passwordd).split
if len(lengt) < 6 and len(lengt) > 16:
raise FormulaError("You should entry between 6 and 16 charachters!")
try:
pass_cont = list(string.ascii_letters + string.digits + string.punctuation)
passwordd = pass_cont
except ValueError as ve:
raise FormulaError(ve)
finally:
print('This is always executed')

while True:
passwordd = str(stdiomask.getpass(prompt="Please set a password!: ", mask="S")) # I used 'stdiomask' modelu.
if passwordd == "0":
break
print(password())