diff --git a/4.1.py b/4.1.py new file mode 100644 index 0000000..27d4367 --- /dev/null +++ b/4.1.py @@ -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") diff --git a/4.2.py b/4.2.py new file mode 100644 index 0000000..e735721 --- /dev/null +++ b/4.2.py @@ -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) diff --git a/4.3.main.py b/4.3.main.py new file mode 100644 index 0000000..f340a49 --- /dev/null +++ b/4.3.main.py @@ -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)) + diff --git a/4.4.py b/4.4.py new file mode 100644 index 0000000..f149424 --- /dev/null +++ b/4.4.py @@ -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) + + diff --git a/my_dice.py b/my_dice.py new file mode 100644 index 0000000..0bbf20e --- /dev/null +++ b/my_dice.py @@ -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