• Nov 19, 2022 •CodeCatch
0 likes • 1 view
""" Number Guessing Game ---------------------------------------- """ import random attempts_list = [] def show_score(): if len(attempts_list) <= 0: print("There is currently no high score, it's yours for the taking!") else: print("The current high score is {} attempts".format(min(attempts_list))) def start_game(): random_number = int(random.randint(1, 10)) print("Hello traveler! Welcome to the game of guesses!") player_name = input("What is your name? ") wanna_play = input("Hi, {}, would you like to play the guessing game? (Enter Yes/No) ".format(player_name)) // Where the show_score function USED to be attempts = 0 show_score() while wanna_play.lower() == "yes": try: guess = input("Pick a number between 1 and 10 ") if int(guess) < 1 or int(guess) > 10: raise ValueError("Please guess a number within the given range") if int(guess) == random_number: print("Nice! You got it!") attempts += 1 attempts_list.append(attempts) print("It took you {} attempts".format(attempts)) play_again = input("Would you like to play again? (Enter Yes/No) ") attempts = 0 show_score() random_number = int(random.randint(1, 10)) if play_again.lower() == "no": print("That's cool, have a good one!") break elif int(guess) > random_number: print("It's lower") attempts += 1 elif int(guess) < random_number: print("It's higher") attempts += 1 except ValueError as err: print("Oh no!, that is not a valid value. Try again...") print("({})".format(err)) else: print("That's cool, have a good one!") if __name__ == '__main__': start_game()
• Feb 26, 2023 •wabdelh
#84 48 13 20 61 20 33 97 34 45 6 63 71 66 24 57 92 74 6 25 51 86 48 15 64 55 77 30 56 53 37 99 9 59 57 61 30 97 50 63 59 62 39 32 34 4 96 51 8 86 10 62 16 55 81 88 71 25 27 78 79 88 92 50 16 8 67 82 67 37 84 3 33 4 78 98 39 64 98 94 24 82 45 3 53 74 96 9 10 94 13 79 15 27 56 66 32 81 77 # xor a list of integers to find the lonely integer res = a[0] for i in range(1,len(a)): res = res ^ a[i]
• Sep 9, 2023 •AustinLeath
0 likes • 24 views
print("test")
• May 31, 2023 •CodeCatch
0 likes • 0 views
# Function to check Armstrong number def is_armstrong_number(number): # Convert number to string to iterate over its digits num_str = str(number) # Calculate the sum of the cubes of each digit digit_sum = sum(int(digit) ** len(num_str) for digit in num_str) # Compare the sum with the original number if digit_sum == number: return True else: return False # Prompt user for a number number = int(input("Enter a number: ")) # Check if the number is an Armstrong number if is_armstrong_number(number): print(number, "is an Armstrong number.") else: print(number, "is not an Armstrong number.")
• Mar 10, 2021 •Skrome
0 likes • 2 views
import string def caesar(text, shift, alphabets): def shift_alphabet(alphabet): return alphabet[shift:] + alphabet[:shift] shifted_alphabets = tuple(map(shift_alphabet, alphabets)) final_alphabet = "".join(alphabets) final_shifted_alphabet = "".join(shifted_alphabets) table = str.maketrans(final_alphabet, final_shifted_alphabet) return text.translate(table) plain_text = "Hey Skrome, welcome to CodeCatch" print(caesar(plain_text, 8, [string.ascii_lowercase, string.ascii_uppercase, string.punctuation]))
class Rectangle: pass class Square(Rectangle): pass rectangle = Rectangle() square = Square() print(isinstance(rectangle, Rectangle)) # True print(isinstance(square, Rectangle)) # True print(isinstance(square, Square)) # True print(isinstance(rectangle, Square)) # False