Share your repls and programming experiences

← Back to all posts
The Guessing Game!
Renise (15)

This is the guessing game, you must guess the computer's number. There are 2 rounds and well the description is told to you in the game.. Give some suggestions and feedback on the game, I am a beginner so yeah!

Comments
hotnewtop
elipie (379)

hello! cool program! instead of just picking a random number for the code this can be done! :

import random
import os
num = random.randint(1,100)#can be  more than just a hundred

# something to spice it up:
guesses = 15#edit this to your liking
print(num)
for i in range(guesses):
  
  num_guess = int(input("What is your guess?\n>"))
  try:   
    if num_guess > num:
      os.system('clear')
      print("Too high!\nYou have "+str(guesses)+" more guesses!")
      guesses = guesses - 1    
    elif num_guess < num:
      os.system('clear')
      print("Too low!\nYou have "+str(guesses)+" More guesses")
      guesses = guesses - 1
    
    else:
      os.system('clear')
      print("You got it!\nWith "+str(guesses)+" guesses left!")
      break
      guesses = guesses - 1
 
  except:
    os.system('clear')
    print("Enter a number!!")
    break
  if guesses == 0:
    print("Oh no! You ran out of guesses!! The number was: "+str(num))

str() basically tells python it is a string, because if you just put

variable = 1234
print("Hello, "+variable)

That will generate an error, because python thinks you are trying to add the string Hello, with the number 1234 which is impossible.

Thanks for reading!!

Also line 34 there is an extra )

Renise (15)

@elipie Omg thank you so much! I will try it out :D

Renise (15)

@elipie Ok I finished, try it out! If you like it upvote :D (Btw i credit you at the end again thank you)

Gr8est (39)

You have an error

Gr8est (39)

@Renise, when I run it, it is saying:
File "main.py", line 34
print("Have a great day!") )
SyntaxError: unmatched ')'

Renise (15)

@CrashBatBat Okay, I will fix it now, thank you for the feedback!

Renise (15)

@CrashBatBat Ok I fixed it, try it now :)

Gr8est (39)

Nice, it's pretty good. ;-)

Renise (15)

@CrashBatBat Yayyy this is my first functional code :D thanks for the support

[deleted]

I cant talk to you anymore, cya in 2 months

[deleted]

@Renise hiiii

[deleted]

@Renise :::DDDD

Renise (15)

@ctimxd can u join le game cook n serve?

[deleted]

@Renise can u add me to it
I removed myself

[deleted]

@Renise nvm im there

Renise (15)

@ctimxd ahhh sorry cya wednesday ;p;