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 Week04_Hw_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'''
## 1. Password
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

control1="^.*(?=.*[a-z]).*$"
control2="^.*(?=.*[A-Z]).*$"
control3="^.*(?=.*[0-9]).*$"
control4="^.*(?=.*[$#@]).*$"
control5="^.*(?=.{6,16}).*$"

def password_validation(password):
if bool(re.search(control1,password))==False:
raise ValueError("This password is not valid. You should use at least one lower letter.")
elif bool(re.search(control2,password))==False:
raise ValueError("This password is not valid. You should use at least one upper letter.")
elif bool(re.search(control3,password))==False:
raise ValueError("This password is not valid. You should use at least one digit.")
elif bool(re.search(control4,password))==False:
raise ValueError("This password is not valid. You should use at least one of them ($,#,@).")
elif bool(re.search(control5,password))==False:
raise ValueError("This password is not valid. You should use at least 6 characters and max 16 chacters.")
else:
return 'Password is valid.'
print(password_validation(input(""))) # aAzc1$22
26 changes: 26 additions & 0 deletions Week04_Hw_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'''
## 2. Dice Percentage
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 math
import random

Dice=[0,0,0,0,0,0]

for i in range(5000):
Dice[random.randint(1,6)-1]+=1
for i in range(5):
print('Percentage of throws of value {} = {:.2f}%'.format(i+1,(Dice[i]/5000)*100))

##print('Percentage of throws of value {} = {:.2f}%'.format(i+1,(Dice[i]/5000)*100))
print(Dice)

10 changes: 10 additions & 0 deletions main01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#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
repetitions_number = int(input("How many times do you want to roll:"))
W_number = int(input("which number's percentage:"))
print("The probability ",W_number, my_dice.rollDice(repetitions_number, W_number), "%")
9 changes: 9 additions & 0 deletions my_dice01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def rollDice(repetitions_number, W_number):
import random
dice = [0, 0, 0, 0, 0, 0]

for i in range(repetitions_number):
x = random.randrange(1, 7)
dice[x-1]+=1
percentage= dice[W_number-1]/repetitions_number*100
return percentage