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
57 changes: 57 additions & 0 deletions assignment_1.py
Original file line number Diff line number Diff line change
@@ -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





23 changes: 23 additions & 0 deletions assignment_2.py
Original file line number Diff line number Diff line change
@@ -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))
61 changes: 61 additions & 0 deletions assignment_4.py
Original file line number Diff line number Diff line change
@@ -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)

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





from my_dice import rollDice

number=int(input("Enter repetition number: "))

print(rollDice(number))
11 changes: 11 additions & 0 deletions my_dice.py
Original file line number Diff line number Diff line change
@@ -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)