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
23 changes: 23 additions & 0 deletions 4.1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import re
while True :
x = input("Write a password : ")
try :
assert len(x) >6 and len(x) <16, 'Your password must be between 6 and 16'
if not re.search("[a-z]", x):
raise ValueError('You must use at least a letter between [a,z]')
elif not re.search("[A-Z]", x):
raise ValueError('You must use at least a letter between [A-Z]')
elif not re.search("[0-9]", x):
raise ValueError('You must use at least a number between [0-9]')
elif not re.search("[#@$]", x):
raise ValueError('You must use special character')

except ValueError as V :
print(V)
except AssertionError as A:
print(A)
else :
print("Successful Password.")
break
finally:
print("Have a Nice Day")
17 changes: 17 additions & 0 deletions 4.2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import random as r
import array as a

dice = a.array('i', [0,0,0,0,0,0])
rolledtimes = 0
def roll():
rand = r.randrange(1,7)
return rand
for i in range(1,5001):
number = roll()
dice.append(number)
rolledtimes+=1
count = [dice.count(1),dice.count(2),dice.count(3),dice.count(4),dice.count(5),dice.count(6)]
for i in range(0,6):
print('The probability is : ')
per = str("{:.2f}".format((count[i] / 5000)*100)) + '%'
print(i + 1, '>>', per)
10 changes: 10 additions & 0 deletions 4.3.main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import my_dice

num = int(input("Enter repetition number: "))

percentages = my_dice.rollDice(num)

for i in range(6):
per = percentages[i]/num * 100
print("The probability of {} is {:.2f}".format(i+1, per))

17 changes: 17 additions & 0 deletions 4.4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import math

input_num = int(input("Please enter the number of inputs: "))

gcd = int(input())

for i in range(input_num-1):
try:
num = int(input())
except:
print("invalid input")
else:
gcd = math.gcd(gcd, num)

print("greatest common divisor", gcd)


8 changes: 8 additions & 0 deletions my_dice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import random

def rollDice(number):
dice = [0] * 6
for i in range(number):
x = random.randint(1,6)
dice[x-1] = dice[x-1] + 1
return dice