From 1a67e5430f23ef15e8ab43c418f954412b615310 Mon Sep 17 00:00:00 2001 From: Yusuf <61010065+codeveloper-ysf@users.noreply.github.com> Date: Wed, 3 Feb 2021 15:09:20 +0100 Subject: [PATCH 1/5] Add files via upload --- least_common_multiple.py | 27 +++++++++++++++++++++++++++ number_guessing.py | 22 ++++++++++++++++++++++ password_generator.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 least_common_multiple.py create mode 100644 number_guessing.py create mode 100644 password_generator.py diff --git a/least_common_multiple.py b/least_common_multiple.py new file mode 100644 index 0000000..16a4470 --- /dev/null +++ b/least_common_multiple.py @@ -0,0 +1,27 @@ +import math + +numbers = [] +while True: + if len(numbers) == 4: + break + else: + try: + number = int(input("type a number: ")) + numbers.append(number) + except ValueError: + print("your entry must be a number!") + + +def lcm(a, i): + b = numbers[i] + result = abs(a*b) // math.gcd(a, b) + print(a, b, result) + if i == len(numbers) - 1: + return result + else: + i += 1 + return lcm(result, i) + + +result = lcm(numbers[0], 1) +print(result) diff --git a/number_guessing.py b/number_guessing.py new file mode 100644 index 0000000..1741e48 --- /dev/null +++ b/number_guessing.py @@ -0,0 +1,22 @@ +import random +import time + +starting_point = int(input("type a starting point: ")) +ending_point = int(input("type an ending point: ")) +computer_guess = random.randint(starting_point, ending_point+1) +guess_counter = 0 +guess_start_time = time.time() + +while True: + player_guess = int(input("guess a number: ")) + guess_counter += 1 + if player_guess == computer_guess: + guess_end_time = time.time() + duration = guess_end_time - guess_start_time + print("player's guess is same with computer's guess\n" + + "guessing amount: {}\n".format(guess_counter) + "guessing duration: {}\n".format(round(duration, 2))) + break + elif player_guess < computer_guess: + print("player's guess is lower than computer's guess") + elif player_guess > computer_guess: + print("player's guess is higher than computer's guess") diff --git a/password_generator.py b/password_generator.py new file mode 100644 index 0000000..4ce1ceb --- /dev/null +++ b/password_generator.py @@ -0,0 +1,36 @@ +import tkinter +import random +import string +from tkinter.constants import BOTTOM, CENTER, RAISED + +upper_letter = string.ascii_uppercase +lower_letter = string.ascii_lowercase +digit = string.digits +symbol = string.punctuation +all_randoms = upper_letter + lower_letter + digit + symbol + +top = tkinter.Tk() +top.title("password generator") +top.geometry("400x400") +var = tkinter.StringVar() +password_label = tkinter.Label( + top, textvariable=var, relief=RAISED, width=20, height=5) + + +def generator(): + uppers = random.choices(upper_letter, k=2) + digits = random.choices(digit, k=2) + symbols = random.choices(symbol, k=2) + rest_of_password = random.choices(all_randoms, k=4) + raw_password = uppers + digits + symbols + rest_of_password + random.shuffle(raw_password) + password = "".join(raw_password) + print(password) + var.set("password: " + password) + password_label.pack() + + +button = tkinter.Button(top, text="generate", + command=generator, width=20, height=5) +button.pack() +top.mainloop() From 9dc45dcc600438a275ecfdac570143f2c2744369 Mon Sep 17 00:00:00 2001 From: Yusuf <61010065+codeveloper-ysf@users.noreply.github.com> Date: Wed, 3 Feb 2021 15:10:44 +0100 Subject: [PATCH 2/5] Create mis_calculator --- mis_calculator | 1 + 1 file changed, 1 insertion(+) create mode 100644 mis_calculator diff --git a/mis_calculator b/mis_calculator new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/mis_calculator @@ -0,0 +1 @@ + From 119b24c6f0dd232f3bf0fc63b1906cbe1e174038 Mon Sep 17 00:00:00 2001 From: Yusuf <61010065+codeveloper-ysf@users.noreply.github.com> Date: Wed, 3 Feb 2021 15:11:09 +0100 Subject: [PATCH 3/5] Delete mis_calculator --- mis_calculator | 1 - 1 file changed, 1 deletion(-) delete mode 100644 mis_calculator diff --git a/mis_calculator b/mis_calculator deleted file mode 100644 index 8b13789..0000000 --- a/mis_calculator +++ /dev/null @@ -1 +0,0 @@ - From 10395ec70b3666679646953eb9095f646e86dd20 Mon Sep 17 00:00:00 2001 From: Yusuf <61010065+codeveloper-ysf@users.noreply.github.com> Date: Wed, 3 Feb 2021 15:12:44 +0100 Subject: [PATCH 4/5] Create readme.md --- mis_calculator/readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 mis_calculator/readme.md diff --git a/mis_calculator/readme.md b/mis_calculator/readme.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/mis_calculator/readme.md @@ -0,0 +1 @@ + From 08f0bd7ff02886de31a30325b0d1f2a00516bd76 Mon Sep 17 00:00:00 2001 From: Yusuf <61010065+codeveloper-ysf@users.noreply.github.com> Date: Wed, 3 Feb 2021 15:13:13 +0100 Subject: [PATCH 5/5] Add files via upload --- mis_calculator/addition.py | 2 ++ mis_calculator/calculator.py | 46 ++++++++++++++++++++++++++++++++ mis_calculator/division.py | 5 ++++ mis_calculator/multiplication.py | 2 ++ mis_calculator/subtraction.py | 2 ++ 5 files changed, 57 insertions(+) create mode 100644 mis_calculator/addition.py create mode 100644 mis_calculator/calculator.py create mode 100644 mis_calculator/division.py create mode 100644 mis_calculator/multiplication.py create mode 100644 mis_calculator/subtraction.py diff --git a/mis_calculator/addition.py b/mis_calculator/addition.py new file mode 100644 index 0000000..bd37e6c --- /dev/null +++ b/mis_calculator/addition.py @@ -0,0 +1,2 @@ +def addition(a, b): + return a + b diff --git a/mis_calculator/calculator.py b/mis_calculator/calculator.py new file mode 100644 index 0000000..700eecc --- /dev/null +++ b/mis_calculator/calculator.py @@ -0,0 +1,46 @@ +import math +import addition +import subtraction +import multiplication +import division + +result = 0 +operations = ["1", "2", "3", "4"] + +while True: + operation = input( + "addition: 1\nsubtraction: 2\nmultiplication: 3\ndivision: 4\n\nchoose an operation: ") + if operation not in operations: + print("type a valid operation!\n") + else: + while True: + try: + a = float(input("type a number: ")) + b = float(input("type a number: ")) + break + except ValueError: + print("type a valid number!\n") + if operation == "1": + result = addition.addition(a, b) + elif operation == "2": + result = subtraction.subtraction(a, b) + elif operation == "3": + result = multiplication.multiplication(a, b) + elif operation == "4": + result = division.division(a, b) + + if type(result) == str: + print(result) + else: + print(math.ceil(result)) + yes_or_no = input( + "\nfor a new operation, type 'Y'.\nto exit, type 'N'. \nyour choice: ") + while yes_or_no.upper() != "Y" and yes_or_no.upper() != "N": + print("type 'Y' or 'N'!") + yes_or_no = input( + "\nfor a new operation, type 'Y'.\nto exit, type 'N'. \nyour choice: ") + if yes_or_no.upper() == "N": + print("bye!") + break + elif yes_or_no.upper() == "Y": + continue diff --git a/mis_calculator/division.py b/mis_calculator/division.py new file mode 100644 index 0000000..645956b --- /dev/null +++ b/mis_calculator/division.py @@ -0,0 +1,5 @@ +def division(a, b): + try: + return a / b + except ZeroDivisionError: + return "entry can not be 0" diff --git a/mis_calculator/multiplication.py b/mis_calculator/multiplication.py new file mode 100644 index 0000000..8454ea0 --- /dev/null +++ b/mis_calculator/multiplication.py @@ -0,0 +1,2 @@ +def multiplication(a, b): + return a * b diff --git a/mis_calculator/subtraction.py b/mis_calculator/subtraction.py new file mode 100644 index 0000000..49071f9 --- /dev/null +++ b/mis_calculator/subtraction.py @@ -0,0 +1,2 @@ +def subtraction(a,b): + return a - b \ No newline at end of file