#!/usr/bin/python
import os
from random import randint
def check_guess(target_number, guessed_number):
'Function to check whether a guessed number matches the the target number'
odd_numbers = [number for number in range(1,99,2)]
even_numbers = [number for number in range(2,100,2)]
if guessed_number == target_number:
return True
elif guessed_number > target_number:
difference = guessed_number - target_number
if difference > 20:
how_wrong = "WAY too High"
else:
how_wrong= "Too high!"
print(how_wrong)
if target_number in odd_numbers:
print("Clue: It is an odd number")
return False
else:
print("Too low")
if target_number in even_numbers:
print("Clue: It is an even number")
return False
def show_game_menu(score):
'Function to show the user options to quit or start a new game'
if os.name == 'posix':
os.system("clear")
else:
os.system("cls")
print("---------------------------------")
print("Welcome to Guessy Numz!")
print("---------------------------------")
chosen_option = input("Quit (q), New Game (n), Show Score (s)")
if chosen_option == 'q':
close_game(score)
elif chosen_option == 'n':
new_game(score)
elif chosen_option == 's':
print("Your score currently is ", score)
input("Press the [Enter] key to continue...")
show_game_menu(score)
else:
print("Else??")
def new_game(score):
'Main function for gameplay'
round_active = True
num_of_guesses = 0
print("Guess the number between 1 and 100")
while round_active == True:
guessed_number = int(input("Your Guess: "))
if check_guess(target_number, guessed_number):
score = score + 1
num_of_guesses += 1
print("Correct! You used ",num_of_guesses," guesses.")
print("Your score is now ", score)
input("Press the [Enter] key to continue...")
show_game_menu(score)
else:
num_of_guesses+=1
round_active = True
def close_game(score):
print("Thanks for playing Guessy Numz. Your final score was ", score, ". Bye!")
exit(0)
score = 0
target_number = randint(0,100)
game_active = True
while game_active == True:
show_game_menu(score)