From 0b217b3565456f681498a214bd74f75fe0924936 Mon Sep 17 00:00:00 2001 From: yasindindar <77322841+yasindindar@users.noreply.github.com> Date: Wed, 3 Feb 2021 14:31:26 +0100 Subject: [PATCH] Week-4 --- 1-Random Password.py | 52 +++++++++++++++++++++++++++++ 2-The Least Common Multiple.py | 31 ++++++++++++++++++ 3-Number Guessing Game.py | 27 +++++++++++++++ 4- Mis Calculator.py | 60 ++++++++++++++++++++++++++++++++++ Addition.py | 2 ++ Division.py | 2 ++ Multiplication.py | 2 ++ Subtraction.py | 2 ++ 8 files changed, 178 insertions(+) create mode 100644 1-Random Password.py create mode 100644 2-The Least Common Multiple.py create mode 100644 3-Number Guessing Game.py create mode 100644 4- Mis Calculator.py create mode 100644 Addition.py create mode 100644 Division.py create mode 100644 Multiplication.py create mode 100644 Subtraction.py diff --git a/1-Random Password.py b/1-Random Password.py new file mode 100644 index 0000000..c845ed4 --- /dev/null +++ b/1-Random Password.py @@ -0,0 +1,52 @@ +import random +import string +from tkinter import * + + +def password_generator(): + result = "" + for i in range(1, 11): + result = result + random.choices( + string.ascii_uppercase + string.digits + string.punctuation + string.ascii_lowercase).pop() + + return result + + +def is_suitable_password(password): + upper_case_count = 0 + lower_case_count = 0 + digit_count = 0 + symbol_count = 0 + + for i in password: + if string.ascii_lowercase.count(i) > 0: + lower_case_count += 1 + elif string.ascii_uppercase.count(i) > 0: + upper_case_count += 1 + elif string.punctuation.count(i) > 0: + symbol_count += 1 + else: + digit_count += 1 + + if digit_count >= 2 and upper_case_count >= 2 and symbol_count >= 2: + return True + else: + return False + + +def press(): + while True: + + new_password = password_generator() + if is_suitable_password(new_password) is True: + l1.config(text=new_password) + break + + +main_frame = Tk(className=" Password Generator App") +main_frame.geometry("400x400") +b1 = Button(main_frame, text="Generate password", command=press).pack() +l1 = Label(main_frame, text="Welcome") +l1.pack() + +main_frame.mainloop() diff --git a/2-The Least Common Multiple.py b/2-The Least Common Multiple.py new file mode 100644 index 0000000..6db03ae --- /dev/null +++ b/2-The Least Common Multiple.py @@ -0,0 +1,31 @@ +import math +gcd = math.gcd + +while True: + try: + a = int(input("Please enter first number: ")) + break + except ValueError: + print("Oops! That was no valid number. Try again...") +while True: + try: + b = int(input("Please enter second number: ")) + break + except ValueError: + print("Oops! That was no valid number. Try again...") + +while True: + try: + c = int(input("Please enter third number: ")) + break + except ValueError: + print("Oops! That was no valid number. Try again...") + +while True: + try: + d = int(input("Please enter fourth number: ")) + break + except ValueError: + print("Oops! That was no valid number. Try again...") + +print("L.C.M. is : " + str(gcd(a, b, c, d))) diff --git a/3-Number Guessing Game.py b/3-Number Guessing Game.py new file mode 100644 index 0000000..b8ab8c7 --- /dev/null +++ b/3-Number Guessing Game.py @@ -0,0 +1,27 @@ +import random +import time + +start_of_serie = int(input("Please enter your selected range's start:")) +end_of_serie = int(input("Please enter your selected range's end:")) +guess_count = 0 +elapsed_time = 0 +computer_selection = random.randint(start_of_serie, end_of_serie + 1) +# print(computer_selection) +start_time = time.time() +user_selection = int(input("Please guess a number from what was your selected range and insert: ")) +guess_count += 1 + +while True: + + if user_selection == computer_selection: + print("Congratulations") + elapsed_time = time.time() - start_time + print("Elapsed time: " + str(elapsed_time)) + print("Guess count: " + str(guess_count)) + break + elif user_selection > computer_selection: + user_selection = int(input("Please guess a smaller number than your guess: ")) + guess_count += 1 + else: + user_selection = int(input("Please guess a bigger number than your guess: ")) + guess_count += 1 diff --git a/4- Mis Calculator.py b/4- Mis Calculator.py new file mode 100644 index 0000000..3d659c5 --- /dev/null +++ b/4- Mis Calculator.py @@ -0,0 +1,60 @@ +import math +from Addition import addition +from Subtraction import subtraction +from Multiplication import multiplication +from Division import division +round_number_ceil = math.ceil + + +def get_number_input(): + while True: + try: + number = float(input("Please enter a float ( with '.' ) number: ")) + break + except ValueError: + print("Oops! That was no valid number. Try again...") + return number + + +def get_operator_symbol(): + while True: + try: + symbol = input("Please enter a mathematical operator symbol (+,-,*,/): ") + if symbol != '+' and symbol != '-' and symbol != '*' and symbol != '/': + raise ValueError + break + except ValueError: + print("Oops! That was no valid symbol. Try again...") + + return symbol + + +def get_y_n_answer(): + while True: + try: + letter = input("Would you like to make another calculation (Y,N): ") + if letter != 'Y' and letter != 'y' and letter != 'N' and letter != 'n': + raise ValueError + break + except ValueError: + print("Oops! That was no valid symbol. Try again...") + + return letter + + +while True: + + operator_symbol = get_operator_symbol() + + if operator_symbol == '+': + print("Result: " + str(round_number_ceil(addition(get_number_input(), get_number_input())))) + elif operator_symbol == '-': + print("Result: " + str(round_number_ceil(subtraction(get_number_input(), get_number_input())))) + elif operator_symbol == '*': + print("Result: " + str(round_number_ceil(multiplication(get_number_input(), get_number_input())))) + elif operator_symbol == '/': + print("Result: " + str(round_number_ceil(division(get_number_input(), get_number_input())))) + + answer_letter = get_y_n_answer() + if answer_letter == 'N' or answer_letter == 'n': + break diff --git a/Addition.py b/Addition.py new file mode 100644 index 0000000..bd37e6c --- /dev/null +++ b/Addition.py @@ -0,0 +1,2 @@ +def addition(a, b): + return a + b diff --git a/Division.py b/Division.py new file mode 100644 index 0000000..3988b57 --- /dev/null +++ b/Division.py @@ -0,0 +1,2 @@ +def division(a, b): + return a / b diff --git a/Multiplication.py b/Multiplication.py new file mode 100644 index 0000000..8454ea0 --- /dev/null +++ b/Multiplication.py @@ -0,0 +1,2 @@ +def multiplication(a, b): + return a * b diff --git a/Subtraction.py b/Subtraction.py new file mode 100644 index 0000000..54fef2b --- /dev/null +++ b/Subtraction.py @@ -0,0 +1,2 @@ +def subtraction(a, b): + return a - b