Created
August 1, 2016 14:59
-
-
Save Miha-Pleskovic/74c0839bc34cecdfa9c2f5b102d15de6 to your computer and use it in GitHub Desktop.
Guess The Secret Number v2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from random import randint | |
# QUITS THE GAME | |
def shut_down(): | |
print "The real secret number is still out there ..." | |
quit() | |
# TUTORIAL | |
def tutorial(): | |
print "Welcome to the game!" | |
print "" | |
print "Your goal is to guess randomly generated hidden number:" | |
print " -- choose your difficulty:" | |
print " -- EASY: generates a number up to 20, helper is ON" | |
print " -- NORMAL: generates a number up to 50, helper is ON" | |
print " -- HARD: generates a number up to 80, helper is OFF" | |
print " -- REALLY HARD: generates a number up to 150, helper is OFF" | |
print " -- try to guess the correct number as quickly as possible" | |
print "" | |
print "If you wish to leave, just type 'give up' and you'll be back in main menu." | |
print "" | |
print "Good luck!" | |
print "" | |
main_menu() | |
# WOULD YOU LIKE TO PLAY AGAIN? | |
def play_again(): | |
print "Would you like to play again? (1 - YES | 2 - NO)" | |
play_again = raw_input("").lower() | |
print "" | |
if play_again == "1" or play_again == "yes": | |
new_game() | |
elif play_again == "2" or play_again == "no" or play_again == "give up": | |
main_menu() | |
else: | |
print "Command unrecognised. Please try again." | |
play_again() | |
# IS THE GUESSING NUMBER CORRECT? HELPER ON | |
def easy_guess(secret_number, guess, counter): | |
if guess.replace(".", "").isdigit() or guess.isdigit(): | |
if guess == str(secret_number): | |
print "CONGRATULATIONS! YOU FOUND THE NUMBER!" | |
print "It took you " + str(counter) + " tries." | |
print "" | |
elif int(guess) < secret_number or float(guess) < secret_number: | |
counter = counter + 1 | |
print "Incorrect. Try a little higher:" | |
guess = raw_input("") | |
print "" | |
easy_guess(secret_number, guess, counter) | |
elif int(guess) > secret_number or float(guess) > secret_number: | |
counter = counter + 1 | |
print "Incorrect. Try a little lower:" | |
guess = raw_input("") | |
print "" | |
easy_guess(secret_number, guess, counter) | |
elif guess.lower() == "give up": | |
main_menu() | |
else: | |
counter = counter + 1 | |
print "Incorrect. You also have other characters in your number. Try again:" | |
guess = raw_input("") | |
print "" | |
easy_guess(secret_number, guess, counter) | |
# IS THE GUESSING NUMBER CORRECT? | |
def hard_guess(secret_number, guess, counter): | |
if guess == str(secret_number): | |
print "CONGRATULATIONS! YOU FOUND THE NUMBER!" | |
print "It took you " + str(counter) + " tries." | |
print "" | |
elif guess.lower() == "give up": | |
main_menu() | |
else: | |
counter = counter + 1 | |
print "Incorrect. Try again:" | |
guess = raw_input("") | |
print "" | |
hard_guess(secret_number, guess, counter) | |
# PLAYS THE GAME ON EASY | |
def easy_game(): | |
counter = 1 | |
secret_number = randint(1, 20) | |
print "Generating a number ..." | |
print "." | |
print "." | |
print "." | |
print "The number has been selected!" | |
print "Guess the number:" | |
guess = raw_input("") | |
print "" | |
easy_guess(secret_number, guess, counter) | |
play_again() | |
# PLAYS THE GAME ON NORMAL | |
def normal_game(): | |
counter = 1 | |
secret_number = randint(1, 50) | |
print "Generating a number ..." | |
print "." | |
print "." | |
print "." | |
print "The number has been selected!" | |
print "Guess the number:" | |
guess = raw_input("") | |
print "" | |
easy_guess(secret_number, guess, counter) | |
play_again() | |
# PLAYS THE GAME ON HARD | |
def hard_game(): | |
counter = 1 | |
secret_number = randint(1, 80) | |
print "Generating a number ..." | |
print "." | |
print "." | |
print "." | |
print "The number has been selected!" | |
print "Guess the number:" | |
guess = raw_input("") | |
print "" | |
hard_guess(secret_number, guess, counter) | |
play_again() | |
# PLAYS THE GAME ON REALLY HARD | |
def x_hard_game(): | |
counter = 1 | |
secret_number = randint(1, 150) | |
print "Generating a number ..." | |
print "." | |
print "." | |
print "." | |
print "The number has been selected!" | |
print "Guess the number:" | |
guess = raw_input("") | |
print "" | |
hard_guess(secret_number, guess, counter) | |
play_again() | |
# PLAYS THE GAME | |
def new_game(): | |
print "Choose your difficulty:" | |
print "1 -- EASY (up to 20, helper ON)" | |
print "2 -- NORMAL (up to 50, helper ON)" | |
print "3 -- HARD (up to 80, helper OFF)" | |
print "4 -- REALLY HARD (up to 150, helper OFF)" | |
difficulty = raw_input("").lower() | |
print "" | |
if difficulty == "1": | |
easy_game() | |
elif difficulty == "2": | |
normal_game() | |
elif difficulty == "3": | |
hard_game() | |
elif difficulty == "4": | |
x_hard_game() | |
elif difficulty == "give up": | |
main_menu() | |
else: | |
print "Command unrecognised. Please try again." | |
new_game() | |
# MAIN MENU | |
def main_menu(): | |
print "1 -- NEW GAME" | |
print "2 -- TUTORIAL" | |
print "3 -- QUIT" | |
choice = raw_input("") | |
print "" | |
if choice == "1": | |
new_game() | |
elif choice == "2": | |
tutorial() | |
elif choice == "3": | |
shut_down() | |
else: | |
print "Command unknown. Please try again." | |
main_menu() | |
# PROGRAM STARTS HERE | |
print "" | |
print "|/////////////////////////////////////////|" | |
print "| |" | |
print "| GUESS THE SECRET NUMBER II |" | |
print "| |" | |
print "|/////////////////////////////////////////|" | |
print "" | |
main_menu() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment