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
36 changes: 36 additions & 0 deletions Password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""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.
If password is not valid throw ValueError with a proper error message
for each rule. If the password is valid print a success message.
Use some from raise, except, assert, else and finally keywords."""


import re
p= input("Input your password :")
x = True
while x:
if (len(p)<6 or len(p)>16):
raise ValueError ("Length has to be between 6-16 characters.")
elif not re.search("[a-z]",p):
raise ValueError('You have to "$","#","@"')
elif not re.search("[0-9]",p):
raise ValueError("You should use at least one digit number.")
elif not re.search("[A-Z]",p):
raise ValueError("A capital letter must be used.")
elif not re.search("[$#@]",p):
raise ValueError("A symbol must be used.")

else:
print("Valid Password")
x=False
break

print("\n Your password is : ",p)

38 changes: 38 additions & 0 deletions TheGcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""As a user, I want to use a program which can calculate the greatest common divisor (GCD) of my inputs.

Acceptance Criteria:

Ask user the enter the number of inputs (n).
Ask user to enter n input numbers one by one.
Use try/except blocks to verify input entries and warn the user for Nan or non numerical inputs.
Calculate the greatest common divisor (GCD) of n numbers.
Use gcd function in module of math."""


import math
def TheGCD():
i=0

n = int(input("Enter number of elements : "))
lst=[]
if n<0:
raise ValueError("Number of elements must be higher than zero")
else:
while i<n :

try :

numbers=int(input("Press ↵ after each number : "))
except ValueError :
print("Enter valid integer numbers.")
a=input(f"Enter Q for quit,\nPress'C' for continue and enter {n-i} numbers to complete :")
if a=="Q":
break
elif a=="C":
continue

else :
lst.append(numbers)
i += 1
return print(f"TheGCD of {len(lst)} number(s) :",math.gcd(*lst))
TheGCD()
23 changes: 23 additions & 0 deletions dice.per.5000.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""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.

If the value is 1, increase the element 0 in the array by 1, the same applies to the values 2, 3, 4, 5 and 6.
The dice[0] element indicates the number of times value 1 has occurred.
Or in general: dice[x-1] indicates the number of times that x has been thrown.
At the end of the repetition, print the contents of the array as percentages with 2 decimal places.
For example; "Percentage of throws of value 3 = 16.28%"""

import random
dice=[0,0,0,0,0,0] # dices in order, [1,2,3,4,5,6] .we will only add number of rounds
for i in range(5000):
lucky_n = random.randint(1,6) #this generates dice for current round
for n in range (1,7):
if lucky_n==n: #current dice will be added in list of dice(only +1 per round)
dice[n-1]+=1
Per=[]
for i in range(6):
current=(dice[i]/50) #generates percentages for (1,6)
Per.append(current) #and add list(Per)
for i in range(6):
print("Percentage of throws of Value {} :".format(i+1),str(Per[i])+" %")

18 changes: 18 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Create a Python module called my_dice.py and export the code
you wrote in question 2 into a function called rollDice(number).

Changes:

Instead of repetition of 5000 times, makes a repetition of times of given number variable.
Instead of printing, return the array of percentages.
Then create a new module called main.py. Gets an input from the user using "Enter repetition number: ".
Then call rollDice method with this user input. Lastly, print each probability. E.g. "The probability of 0 is 16.20"""

import my_dice

def dice_p(t):
percentages=(my_dice.rollDice(t))

for i in range(6):
print("The probability of {} is {} %".format((i+1),percentages[i]))
dice_p(t=int(input("Enter repitition number :")))
25 changes: 25 additions & 0 deletions my_dice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Create a Python module called my_dice.py and export the code
you wrote in question 2 into a function called rollDice(number).

Changes:

Instead of repetition of 5000 times, makes a repetition of times of given number variable.
Instead of printing, return the array of percentages.
Then create a new module called main.py. Gets an input from the user using "Enter repetition number: ".
Then call rollDice method with this user input. Lastly, print each probability. E.g.
"The probability of 0 is 16.20"""

import random
def rollDice(n):
dice=[0,0,0,0,0,0] # dices in order, [1,2,3,4,5,6] .we will only add number of rounds
Per=[] #list of percentages
for i in range(n):
hand = random.randint(1,6)
for x in range (1,7):
if hand==x: #current dice will be added in list of dice(only +1 per round)
dice[x-1]+=1
for i in range(6):
current=(dice[i]*100/n) #generates percentages for (1,6) in list(dice)
Per.append(current) #and add list(Per)

return Per