diff --git a/README.md b/README.md index 012bd27..da3e237 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# 5-Python-Projects-For-Beginners \ No newline at end of file +# 5-Python-Projects-For-Beginners + +Első commit tartalma, és a második commit tartalma \ No newline at end of file diff --git a/anagram.py b/anagram.py new file mode 100644 index 0000000..1a4ce38 --- /dev/null +++ b/anagram.py @@ -0,0 +1,7 @@ +str1 = input("Enter the First String = ") +str2 = input("Enter the Second String = ") + +if(sorted(str1) == sorted(str2)): + print("Two Strings are Anagrams.") +else: + print("Two Strings are not Anagrams.") \ No newline at end of file diff --git a/anagram_fuggveny.py b/anagram_fuggveny.py new file mode 100644 index 0000000..2596fb1 --- /dev/null +++ b/anagram_fuggveny.py @@ -0,0 +1,5 @@ +def anagram_fuggveny(): + if(sorted(str1) == sorted(str2)): + return "Two Strings are Anagrams." + else: + return "Two Strings are not Anagrams." diff --git a/game.py b/game.py new file mode 100644 index 0000000..28390c8 --- /dev/null +++ b/game.py @@ -0,0 +1,32 @@ +import rps_match +from rps_match import options + + +def game(): + user_wins = 0 + computer_wins = 0 + + while True: + user_input = input("Type Rock/Paper/Scissors or Q to quit: ").lower() + if user_input == "q": + break + + if user_input not in options: + continue + + result = rps_match.rps_match(user_input) + + if result == "user_wins": + print("You won!") + user_wins += 1 + + elif result == "computer_wins": + print("You lost!") + computer_wins += 1 + else: + print("Nobody wins!") + + print("You won", user_wins, "times.") + print("The computer won", computer_wins, "times.") + print("Goodbye!") + diff --git a/monthly_payment_calculator.py b/monthly_payment_calculator.py new file mode 100644 index 0000000..ea18446 --- /dev/null +++ b/monthly_payment_calculator.py @@ -0,0 +1,6 @@ +# calculate monthly payment +def calculate(p: int, months: int, rate: float): + return (rate/12) * (1/(1-(1+rate/12)**(-months)))*p + + + diff --git a/rock_paper_scissors.py b/rock_paper_scissors.py index 3249fe4..e39ba42 100644 --- a/rock_paper_scissors.py +++ b/rock_paper_scissors.py @@ -1,39 +1,3 @@ -import random +import game -user_wins = 0 -computer_wins = 0 - -options = ["rock", "paper", "scissors"] - -while True: - user_input = input("Type Rock/Paper/Scissors or Q to quit: ").lower() - if user_input == "q": - break - - if user_input not in options: - continue - - random_number = random.randint(0, 2) - # rock: 0, paper: 1, scissors: 2 - computer_pick = options[random_number] - print("Computer picked", computer_pick + ".") - - if user_input == "rock" and computer_pick == "scissors": - print("You won!") - user_wins += 1 - - elif user_input == "paper" and computer_pick == "rock": - print("You won!") - user_wins += 1 - - elif user_input == "scissors" and computer_pick == "paper": - print("You won!") - user_wins += 1 - - else: - print("You lost!") - computer_wins += 1 - -print("You won", user_wins, "times.") -print("The computer won", computer_wins, "times.") -print("Goodbye!") +game.game() diff --git a/rps_match.py b/rps_match.py new file mode 100644 index 0000000..5e3d5cb --- /dev/null +++ b/rps_match.py @@ -0,0 +1,24 @@ +import random + +options = ["rock", "paper", "scissors"] + + +def rps_match(user_input_param): + + random_number = random.randint(0, 2) + # rock: 0, paper: 1, scissors: 2 + computer_pick = options[random_number] + print("Computer picked", computer_pick + ".") + + if user_input_param == "rock" and computer_pick == "scissors": + return "user_wins" + + elif user_input_param == "paper" and computer_pick == "rock": + return "user_wins" + + elif user_input_param == "scissors" and computer_pick == "paper": + return "user_wins" + elif user_input_param == computer_pick: + return "nobody wins" + else: + return "computer_wins" diff --git a/test_anagram_fuggveny.py b/test_anagram_fuggveny.py new file mode 100644 index 0000000..345151c --- /dev/null +++ b/test_anagram_fuggveny.py @@ -0,0 +1,11 @@ +def test_anagram_fuggveny(): + str1 = "vér" + str2 = "rév" + assert "Two Strings are Anagrams." + + +def test_anagram_fuggveny(): + str1 = "vér" + str2 = "alma" + assert "Two Strings are not Anagrams." + diff --git a/test_monthly_payment_calculator.py b/test_monthly_payment_calculator.py new file mode 100644 index 0000000..d7372fb --- /dev/null +++ b/test_monthly_payment_calculator.py @@ -0,0 +1,5 @@ +from monthly_payment_calculator import calculate + + +def test_calculate_egymillio_negyev_tizszazalek(): + assert round(calculate(1000000, 48, 0.1)) == 25363 diff --git a/test_rock_paper_scissors.py b/test_rock_paper_scissors.py new file mode 100644 index 0000000..ee227c6 --- /dev/null +++ b/test_rock_paper_scissors.py @@ -0,0 +1,50 @@ +import rps_match +import random + +from unittest.mock import MagicMock + + +def test_rps_match_paper_rock(): + random.randint = MagicMock(return_value=0) + assert rps_match.rps_match("paper") == "user_wins" + + +def test_rps_match_paper_paper(): + random.randint = MagicMock(return_value=1) + assert rps_match.rps_match("paper") == "nobody wins" + + +def test_rps_match_paper_scissors(): + random.randint = MagicMock(return_value=2) + assert rps_match.rps_match("paper") == "computer_wins" + + +def test_rps_match_scissors_rock(): + random.randint = MagicMock(return_value=0) + assert rps_match.rps_match("scissors") == "computer_wins" + + +def test_rps_match_scissors_paper(): + random.randint = MagicMock(return_value=1) + assert rps_match.rps_match("scissors") == "user_wins" + + +def test_rps_match_scissors_scissors(): + random.randint = MagicMock(return_value=2) + assert rps_match.rps_match("scissors") == "nobody wins" + + +def test_rps_match_rock_rock(): + random.randint = MagicMock(return_value=0) + assert rps_match.rps_match("rock") == "nobody wins" + + +def test_rps_match_rock_paper(): + random.randint = MagicMock(return_value=1) + assert rps_match.rps_match("rock") == "computer_wins" + + +def test_rps_match_rock_scissors(): + random.randint = MagicMock(return_value=2) + assert rps_match.rps_match("rock") == "user_wins" +