diff --git a/assignment_1.py b/assignment_1.py new file mode 100644 index 0000000..07aba77 --- /dev/null +++ b/assignment_1.py @@ -0,0 +1,57 @@ +# I. +# 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 +import time + +while True: + + try: + your_password=input("Enter your password: ") + + if not re.search("[a-z]", your_password): + raise ValueError + + elif not re.search("[A-Z]", your_password): + raise ValueError + + elif not re.search("[0-9]", your_password): + raise ValueError + + elif not re.search("[$#@]", your_password): + raise ValueError + + elif len(your_password)<6: + raise ValueError + + elif len(your_password)>16: + raise ValueError + + except ValueError: + time.sleep(1.0) + print("""Please check your password again. + At least one password contains: + one lowercase, one uppercase, one number + one character($#@) + min 6 digits max 16 digits!!!""") + + + else: + print("Your password is valid!!!") + + finally: + print("""Executing Finally...""") + break + + + + + diff --git a/assignment_2.py b/assignment_2.py new file mode 100644 index 0000000..5731564 --- /dev/null +++ b/assignment_2.py @@ -0,0 +1,23 @@ +import random +# II. +# 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%" + + + +# dice=[0]*6 + +# for i in range(5000): +# random_number = random.randrange(1,7) +# dice[random_number-1]+=1 + +# for i in range(6): +# print("Percentage of throws of value {} = {:.2f}%".format(i+1,(dice[i]/5000)*100)) + + +print(range(6)) \ No newline at end of file diff --git a/assignment_4.py b/assignment_4.py new file mode 100644 index 0000000..efb9817 --- /dev/null +++ b/assignment_4.py @@ -0,0 +1,61 @@ +import math +# 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. +lst=[] +n = int(input("Enter the number of repetitions you want to enter: ")) +for i in range(n): + try: + inputs =int(input("Enter the inputs one by one: ")) + + if n>2: + raise SystemError + + elif inputs == 1: + raise KeyError + + + elif inputs != int(inputs): + raise ValueError + + elif inputs<0: + raise RecursionError + + except SystemError: + print(""" + You tried to enter more than 2 inputs!!! + Please try to enter less n! + """) + except KeyError: + print("Input you entered must be bigger than 1!!!") + + + except ValueError: + print("input you entered is not an integer!!!") + + except RecursionError: + print("Opps! Input you entered is negative!!!") + + + else: + lst.append(inputs) + + finally: + print("Next one!") + +result = math.gcd(lst[0],lst[1]) + +if result == 1: + print(""" GCD can not be 1 + Please give the new values! + """) + +else: + print("The greatest common divisor of",lst[0],"and",lst[1],"is",result) + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..dc901a0 --- /dev/null +++ b/main.py @@ -0,0 +1,10 @@ + + + + + +from my_dice import rollDice + +number=int(input("Enter repetition number: ")) + +print(rollDice(number)) diff --git a/my_dice.py b/my_dice.py new file mode 100644 index 0000000..bd3f056 --- /dev/null +++ b/my_dice.py @@ -0,0 +1,11 @@ +import random +def rollDice(number): + + dice=[0]*6 + for i in range(number): + random_number = random.randrange(1,7) + dice[random_number-1]+=1 + + + for i in range(6): + return "The probability of {} = {:.2f}%".format(i+1,(dice[i]/number)*100)