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
27 changes: 27 additions & 0 deletions least_common_multiple.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions mis_calculator/addition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def addition(a, b):
return a + b
46 changes: 46 additions & 0 deletions mis_calculator/calculator.py
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions mis_calculator/division.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def division(a, b):
try:
return a / b
except ZeroDivisionError:
return "entry can not be 0"
2 changes: 2 additions & 0 deletions mis_calculator/multiplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def multiplication(a, b):
return a * b
1 change: 1 addition & 0 deletions mis_calculator/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions mis_calculator/subtraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def subtraction(a,b):
return a - b
22 changes: 22 additions & 0 deletions number_guessing.py
Original file line number Diff line number Diff line change
@@ -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")
36 changes: 36 additions & 0 deletions password_generator.py
Original file line number Diff line number Diff line change
@@ -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()