diff --git a/Gcd.py b/Gcd.py new file mode 100644 index 0000000..1ad80ed --- /dev/null +++ b/Gcd.py @@ -0,0 +1,21 @@ +from math import gcd +import math +numbers = [] +n = int(input("how many numbers?:")) +count=0 +while True: + count+=1 + if count==n+1: + break + try: + number=int(input("enter numbers")) + numbers.append(int(number)) + except ValueError: + print("Enter a valid number") + count-=1 +print(math.gcd(*numbers)) + + + + + diff --git a/basic_import.py b/basic_import.py new file mode 100644 index 0000000..d97f9f8 --- /dev/null +++ b/basic_import.py @@ -0,0 +1,4 @@ +import my_dice +dice=my_dice.rollDice(int(input("Enter repetition number: "))) +for i in range(len(dice)): + print("The probability of {} is {}%".format(i+1,dice[i])) \ No newline at end of file diff --git a/dice_percentage.py b/dice_percentage.py new file mode 100644 index 0000000..27796b1 --- /dev/null +++ b/dice_percentage.py @@ -0,0 +1,28 @@ +import array as arr +import random +dice = arr.array('i',[0,0,0,0,0,0]) +count=0 +while True: + x= random.randint(1,6) + count+=1 + if count== 5001: + break + elif x==1: + dice[0]+=1 + elif x==2: + dice[1]+=1 + elif x==3: + dice[2]+=1 + elif x==4: + dice[3]+=1 + elif x==5: + dice[4]+=1 + elif x==6: + dice[5]+=1 +sum=dice[0]+dice[1]+dice[2]+dice[3]+dice[4]+dice[5] +print("Percentage of throws of value 0:",(dice[0]/sum)*100) +print("Percentage of throws of value 1:",(dice[1]/sum)*100) +print('Percentage of throws of value 2:',(dice[2]/sum)*100) +print("Percentage of throws of value 3:",(dice[3]/sum)*100) +print("Percentage of throws of value 4:",(dice[4]/sum)*100) +print("Percentage of throws of value 5:",(dice[5]/sum)*100) \ No newline at end of file diff --git a/my_dice.py b/my_dice.py new file mode 100644 index 0000000..0e64300 --- /dev/null +++ b/my_dice.py @@ -0,0 +1,7 @@ +from random import randint +def rollDice(number): + dice=[0]*6 #[0,0,0,0,0,0] + for i in range(number): + dice[randint(1,6)-1]+=1 #specify the index => [randint(1,6)-1] + dice=[round((dice[i]/number)*100,2) for i in range(len(dice))] + return dice diff --git a/password.py b/password.py new file mode 100644 index 0000000..78e8f0e --- /dev/null +++ b/password.py @@ -0,0 +1,23 @@ +import re +def password_validity(): + password = input("enter a valid password") + + charRegex = re.compile(r'(\w{6,16})') + lowerRegex = re.compile(r'[a-z]+') + upperRegex = re.compile(r'[A-Z]+') + digitRegex = re.compile(r'[0-9]+') + chaRegex = re.compile(r'[#@$]+') + + if charRegex.findall(password)== []: + raise ValueError('The password must be between 6 and 16 characters.') + elif lowerRegex.findall(password)==[]: + raise ValueError('There should be lowercase letter.') + elif upperRegex.findall(password)==[]: + raise ValueError('There should be uppercase letter.') + elif digitRegex.findall(password)==[]: + raise ValueError('There should be at least one digit.') + elif chaRegex.findall(password)==[]: + raise ValueError('There should be at least one of the shown special symbols.') + else: + print('Valid password') +password_validity() \ No newline at end of file