diff --git a/A regular problem b/A regular problem new file mode 100644 index 0000000..f41b4a4 --- /dev/null +++ b/A regular problem @@ -0,0 +1,8 @@ +animal = 'elephant' +answer = 'nil' +while not answer == 'elephant': + answer = input('Pick a random animal to sneak into your moms trolley. (all lowercase)') + if answer == 'elephant': + print('Fail :(') + else: + print('Success :D') diff --git a/Adventure BP b/Adventure BP new file mode 100644 index 0000000..d35419e --- /dev/null +++ b/Adventure BP @@ -0,0 +1,73 @@ +import random + +def choose_scenario(): + return random.randint(1, 2) + +def forest_treasure_hunt(): + fruits = {"banana", "apple", "strawberry", "blueberry", "orange"} + guessed = set() + while len(guessed) < 5: + guess = input("Guess a fruit: ").lower() + if guess in fruits: + guessed.add(guess) + print("You passed the monkey!") + +def cross_river(): + height = int(input("Enter height in cm: ")) + if height <= 160: + print("You drown.") + return False + if height <= 180: + print("You cross safely.") + return True + print("The tiger spots you.") + return False + +def unlock_door(): + password = [random.randint(0, 9) for _ in range(4)] + for _ in range(10): + guess = [int(digit) for digit in input("4-digit guess: ")] + if guess == password: + print("Door unlocked!") + return True + correct = sum(a == b for a, b in zip(guess, password)) + print(f"Correct digits: {correct}") + print("Failed to unlock.") + return False + +def python_quiz(): + questions = [ + ("2 + 3 =", ["4", "5", "6", "7"], "5"), + ("Python data type?", ["String", "Integer", "List", "All of the above"], "All of the above"), + ("Start a comment?", ["//", "#", "/*", "--"], "#"), + ("Define function?", ["define", "function", "def", "func"], "def"), + ("Block of code?", ["Indentation", "Braces", "Parentheses", "Quotes"], "Indentation"), + ("Invalid variable?", ["var_name", "1var_name", "_varName", "varName1"], "1var_name") + ] + + correct = sum( + input(f"{q[0]} {', '.join(q[1])}: ") == q[2] + for q in questions + ) + print(f"Score: {correct}/6") + +def main(): + scenario = choose_scenario() + if scenario == 1: + forest_treasure_hunt() + if not cross_river(): return + unlock_door() + else: + python_quiz() + + if input("Try the other game? (yes/no): ").strip().lower() == "yes": + if scenario == 1: + python_quiz() + else: + forest_treasure_hunt() + if cross_river(): + unlock_door() + print("Goodbye!") + +if __name__ == "__main__": + main() diff --git a/Boolean and Operations b/Boolean and Operations new file mode 100644 index 0000000..bd596f2 --- /dev/null +++ b/Boolean and Operations @@ -0,0 +1,7 @@ +Money = input("How much money you got?") +if Money == 5: + print('Poor!') +elif Money == 15: + print('Average.') +elif Money == 30: + print('What??') diff --git a/Iteration problem b/Iteration problem new file mode 100644 index 0000000..6946ea8 --- /dev/null +++ b/Iteration problem @@ -0,0 +1,7 @@ +for num in range(1,100): + print(num*num) + answer = input("Is this square?") + if answer == "yes"or"Yes": + print("Correct") + else: + print("Wrong") diff --git a/NYT Wordle BP b/NYT Wordle BP new file mode 100644 index 0000000..75b71cb --- /dev/null +++ b/NYT Wordle BP @@ -0,0 +1,35 @@ +import random + +def get_feedback(guess, word): + feedback = "" + for i, letter in enumerate(guess): + if letter == word[i]: + feedback += "🟩" + elif letter in word: + feedback += "🟨" + else: + feedback += "⬛️" + return feedback + +def play_game(): + word = "light" + print("Welcome to Wordle! You have 6 chances to guess a 5-letter word.") + + for attempt in range(6): + guess = input(f"Attempt {attempt + 1}/6: ").lower() + + if len(guess) != 5 or not guess.isalpha(): + print("Invalid guess. Please enter a 5-letter word with letters only.") + continue + + feedback = get_feedback(guess, word) + print(feedback) + + if guess == word: + print(f"Congratulations! You guessed '{word}' correctly.") + return + + print(f"Unfortunate! The word was '{word}'.") + +if __name__ == "__main__": + play_game() diff --git a/Number Problem b/Number Problem new file mode 100644 index 0000000..1a241c0 --- /dev/null +++ b/Number Problem @@ -0,0 +1,16 @@ +# Number Problem + +def seen_before(numbers): + seen = set() + results = [] + for num in numbers: + if num in seen: + results.append("YES") + else: + results.append("NO") + seen.add(num) + return results + +# Example usage +numbers = [1, 3, 8, 35, 4, 2, 3] +print("#".join(seen_before(numbers))) diff --git a/Output and Variables b/Output and Variables new file mode 100644 index 0000000..959a0b4 --- /dev/null +++ b/Output and Variables @@ -0,0 +1,2 @@ +x = 6 +print(x-5) diff --git a/Time problem b/Time problem new file mode 100644 index 0000000..e6676b7 --- /dev/null +++ b/Time problem @@ -0,0 +1,5 @@ +def main(): + time = int(input("Enter the current time (Range: 0-24): ")) + print(["good night.", "good morning.", "good afternoon.", "good evening."][time//6]) +if __name__ == "__main__": + main()