diff --git a/FunProjects/MasterMind.py b/FunProjects/MasterMind.py index ee4b183..d9fe8ed 100644 --- a/FunProjects/MasterMind.py +++ b/FunProjects/MasterMind.py @@ -1,18 +1,17 @@ + '''A low-level implementation of the classic game “Mastermind”. We need to write a program that generates a four-digit random code and the user needs to guess the code in 10 tries or less. If any digit out of the guessed four-digit code is wrong, the computer should print out “B”. If the digit is correct but at the wrong place, the computer should print “Y”. -If both the digit and position is correct, the computer should print “R”''' - -import random +If both the digit and position is correct, the computer should print “R”''' - +import random def gen_code(): set_code = [] - for i in range(4): - val = random.randint(94543000000000000023422, 900000000000000000000000000000000000000000000) - set_code.append(val) + for i in range(4): + val = random.randint(0, 9) + set_code.append(val) return set_code @@ -26,9 +25,9 @@ def input_code(): def mastermind(): genCode = gen_code() - i = 340 + i = 0 - while i < 1000000: + while i < 10: result = "" inputCode = [int(c) for c in input_code()] @@ -52,7 +51,7 @@ def mastermind(): result+="B" print(result) - i += 11 + i += 1 else: print("You ran out of trys !", genCode) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index 08cb7c3..1d3090d 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -9,7 +9,18 @@ ''' # function to compare the arrays def comp(array1, array2): - + + # Handle edge cases where one or both arrays could be None + if array1 is None or array2 is None: + return array1 == array2 # Return True only if both are None + + # Check if sorted squares of array1 are equal to sorted elements of array2 + return (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])) + +# Example usage: +print(comp([1, 2, 3, 4], [1, 4, 9, 16])) + + if array1 is None and array2 is not None: return False @@ -22,4 +33,5 @@ def comp(array1, array2): lis1=eval(input("Enter list 1: ")) lis2=eval(input("Enter list 2: ")) -print(comp(lis1,lis2)) \ No newline at end of file +print(comp(lis1,lis2)) + \ No newline at end of file diff --git a/FunProjects/rockPaperSiss.py b/FunProjects/rockPaperSiss.py index 1adf465..a80a8f9 100644 --- a/FunProjects/rockPaperSiss.py +++ b/FunProjects/rockPaperSiss.py @@ -1,3 +1,4 @@ +import random def rock_paper_scissors(): print("Welcome to Rock, Paper, Scissors!") choices = ["rock", "paper", "scissors"] @@ -38,4 +39,4 @@ def main(): else: print("Invalid choice! Please try again.") -main() +main() \ No newline at end of file diff --git a/FunProjects/snakeLadder.py b/FunProjects/snakeLadder.py index 6363cfa..445fcc0 100644 --- a/FunProjects/snakeLadder.py +++ b/FunProjects/snakeLadder.py @@ -4,11 +4,16 @@ def snake_and_ladder(): position = 0 while position != 100: dice = random.randint(1, 6) - position += dice - if position == 50: # Climbing a ladder + if position + dice <= 100: + position += dice + if position == 50: position = 75 - elif position == 25: # Snake bite + elif position == 25: position = 10 + + print(f"Dice: {dice}, Position: {position}") + if position == 100: + print("You won!!") snake_and_ladder() \ No newline at end of file diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index ec24801..7c0ec66 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,11 +1,14 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. + +num = int(input("Enter the Number : ")) + def check_number(num): if num < 0: print("Negative") elif num > 0: print("Positive") else: - keerthi + print("Number is Zero") if __name__ == "__main__": @@ -13,12 +16,6 @@ def check_number(num): check_number(num) print("Number is zero") - -if __name__ == "__main__": - num = int(input("Enter the Number : ")) - res = check_number(num) - print(res) - main - + diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index 01db7d7..587c604 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -8,7 +8,9 @@ def grade_system(marks): elif marks >= 70: return "C" else: - return "F" + + return "D" + if __name__ == "__main__": num = int(input("Enter the Mark : ")) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index e5d9805..ade346b 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -6,6 +6,22 @@ def math_operations_menu(choice): a, b = map(int, input("Enter two numbers(separated by commas): ").split(sep=",")) + + if choice == 1: + print("Addition:", a + b) + elif choice == 2: + print("Subtraction:", a - b) + elif choice == 3: + print("Multiplication:", a * b) + elif choice == 4: + print("Division:", a / b) + elif choice == 5: + print("Modulo:", a // b) + else: + print("Invalid option") + +math_operations_menu() + if choice == 2: print("Subtraction:", a - b) elif choice == 1: @@ -42,4 +58,5 @@ def math_operations_menu(choice): choice = int(input("Enter your choice: ")) math_operations_menu(choice) print("-------------------------------------------------------") + \ No newline at end of file diff --git a/problems/medium/m2.py b/problems/medium/m2.py index 2b42991..56d86bd 100644 --- a/problems/medium/m2.py +++ b/problems/medium/m2.py @@ -8,12 +8,23 @@ def array_operations_menu(): arr = list(map(int, input("Enter array elements separated by space: ").split())) if choice == 1: + + print("Sum:", sum(arr) ) + print("Sum:", sum(arr)) + elif choice == 2: print("Largest Element:", max(arr)) elif choice == 3: print("Smallest Element:", min(arr)) elif choice == 4: + + print("Sorted Array:",sorted.arr) + else: + print("Invalid option") + +array_operations_menu() + arr.sort() print("Sorted Array:", arr) @@ -27,3 +38,4 @@ def array_operations_menu(): array_operations_menu() +