Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env/python -tt
- #Created by Troy
- """
- This game prompts for the maximum range in which a number
- is generated. The player then has to guess the number generated
- in this range. Feedback is supplied to the player.
- Things to add:
- 1. Game counter
- 2. Try counter
- """
- from sys import exit
- import random
- def again():
- again = '0'
- while again != 'y' and again != 'Y' and again != 'n' and again != 'N':
- again = raw_input("Would you like to play again 'Y/N': ")
- if again == 'y' and again 'Y':
- main()
- elif again == 'n' and again 'N':
- sys.exit(0)
- #Prompts the player for a guess.
- def guess(r):
- ans = int(raw_input("Enter your guess:\n> "))
- while ans != r:
- if ans < r:
- ans = int(raw_input("You're too low. Try again:\n> "))
- elif ans > r:
- ans = int(raw_input("You're too high. Try again:\n> "))
- else:
- ans = int(raw_input("Make sure you're entering an integer. Try again:\n> "))
- else:
- print "You win!\n"
- again()
- #Generates the random integer.
- def intgen(s):
- chosen = random.randint(1, s)
- guess(chosen)
- #This prompts and invokes the random integer generator function.
- def main():
- print "Welcome to the Number Guessing Game!\n"
- max = int(raw_input("Pick a range maximum. Must be an integer\n> "))
- intgen(max)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement