Fandom

Community Central

Comments0

10/3/14 SDD - Creating A Guessing Game: Python

Connorgm March 10, 2014 User blog:Connorgm

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

import math
 
import random
 
 
 
 
loop = 1
 
while loop != 0:
 
  print ("The Guessing game")
 
  print ("Guess the number between 1-100 and win")
 
 
 
 
  start = input("Start? y/n")
 
  if start == "y":
 
      print ("Lets begin")
 
      no = random.randrange(1,100)
 
      print ("I have a number in my head, start guessing")
 
      guesscounter = 10
 
      print(no)
 
 
 
 
      while guesscounter <=10:
 
          guesscounter-=1
 
          guess = input("What number do you think it is?")
 
          guess = int(guess)
 
          if guesscounter <= 0:
 
              print("Soz man, you lost")
 
          elif guess == no:
 
              print("You are a winner, nice.  And it only took", guesscounter, "turns")
 
              break
 
          elif guess != no:
 
              print("Wrong, you have" , guesscounter , "turns left")
 
              if int(guess) < int(no):
 
                  print("try aiming higher")
 
                  print("")
 
              else:
 
                  print("try aiming lower")
 
                  print("")
 
 
 
 
      
 
 
 
 
  print("")
 
  again = input("Again? y/n")
 
  if againt == "n":
 
      loop = 0
 
  elif input == "y":
 
      loop = 1
 
  else:
 
      print("Don't know what you said, repeating")
 
  

    

Also on Fandom

Random Wiki