""" ------------------------------------------------- Project: GUess the number Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: unroe Taratoa Date: Python: 3.5 ------------------------------------------------- '""" # Checking if name has numbers and spaces. Can not contain numbers or spaces def is_valid_name(name): if any(char.isdigit() for char in name): return False if any(char.isspace() for char in name): return False return True # Ask for the player's name while True: name = input("Enter your name (without numbers or spaces): ") if is_valid_name(name): break print("Invalid name. Please try again.") # Greet the player print(f"Hello, {name}! Welcome.") import random # Function to generate a random number def generate_number(): return random.randint(1, 10) # Function to play the game def play_game(player): number_to_guess = generate_number() print(f"{player}, I'm thinking of a number between 1 and 10.") print("Can you guess it?") attempts = 0 while True: guess = int(input("Enter your guess: ")) attempts += 1 if guess < number_to_guess: print("Too low! Try again.") elif guess > number_to_guess: print("Too high! Try again.") else: print(f"Congratulations, {player}! You guessed the number in {attempts} attempts.") break print( ) # Main funcation def main(): print("Welcome to Guess the Number Game!") player1 = input("Enter Player 1's name: ") player2 = input("Enter Player 2's name: ") while True: play_game(player1) play_game(player2) play_again = input("Do you want to play again? (yes/no): ") if play_again.lower() != "yes": break if __name__ == "__main__": main() import random # Function to generate a random number def generate_number(): return random.randint(1, 10) # Function to play the game! def play_game(player): number_to_guess = generate_number() print(f"{player}, I'm thinking of a number between 1 and 100.") print("Can you guess it?") attemps = 0 while True: guess = int(input("Enter your guess: ")) attempts += 1 if guess < number_to_guess: print("Too low! Try again.") elif guess > number_to_guess: print("Too high! Try again.") else: print(f"Congratulations, {player}! You guessed the number in {attempts} attempts.") return attempts # Main function def main(): print("Welcome to Guess the Number Game!") player1 = input("Enter Player 1's name: ") player2 = input("Enter Player 2's name: ") score1 = 0 score2 = 0 round_number = 1 while True: print(f"Round {round_number}:") score1 += play_game(player1) score2 += play_game(player2) round_number += 1 play_again = input("Do you want to play another round? (yes/no): ") if play_again.lower() != "yes": break print("\nFinal Scores:") print(f"{player1}: {score1} points") print(f"{player2}: {score2} points") if score1 > score2: print(f"{player1} wins!") elif score2 > score1: print(f"{player2} wins!") else: print("It's a tie!") print("\nThanks for playing!") if __name__ == "__main__": main() import random # Generate a random number between 1 and 10 number = random.randint(1, 10) print("Welcome to GUESS THE NUMBER!") print("in this game you'll be guessing a number between 1 and 10!.") print("you have 10 guesses") # Ask the player to guess 11 times for guesses_taken in range(1, 11): guess = int(input("Take a guess: ")) # Check if the guess is too low, too high, or correct if guess < number: print("Your guess is too low.") elif guess > number: print("Your guess is too high.") else: break # The guess is correct, break out of the loop # Check if the player guessed the number correctly or ran out of guesses if guess == number: print(f"Congratulations! You guessed the number in {guesses_taken} guesses.") else: print(f"Sorry, the number I was thinking of was {number}.") print(" YOU LOST GAME OVER") print("")