daily pastebin goal
48%
SHARE
TWEET

Number Guessing Game

a guest Jul 12th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env python
  2.  
  3. import os
  4. import random
  5.  
  6. def main():
  7.  
  8.     if os.path.isfile('/home/bod/python/code/insults.txt'):
  9.         insults = 'yes'
  10.         file = open('/home/bod/python/code/insults.txt', 'r')
  11.         list = file.readlines()
  12.     else:
  13.         insults = "no"
  14.  
  15.     print "Welcome to guess the number\n==========================="
  16.     print "\nI'm thinking of a number, you have to guess what it is.\n"
  17.  
  18.     num = random.randrange(100)
  19.     guess = ""
  20.  
  21.     while guess != num:
  22.         guess = int(raw_input("Take a guess: "))
  23.         if guess < num:
  24.             if insults == "yes":
  25.                 print random.choice(list)
  26.             print "Guess higher next time\n"
  27.         elif guess > num:
  28.             if insults == "yes":
  29.                 print random.choice(list)
  30.             print "Guess lower next time\n"
  31.     print "!!***CONGRATULATIONS***!!"
  32.     raw_input()
  33.     if insults == "yes":
  34.         file.close()
  35.  
  36. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top