PLS help with my simple asssignment, a guessing game in python

oops, yea then the condition should be the other way around:

count = 3
while count > 0
   count -= 1

which is still a bit easier then what you had.

But then you should realize that you should swap it around

this for me, is a more logic design. Given the user starts out with 3 guesses, and exits when he has none left

ok thanks for the quick response

I can also make mistakes, i am just a human being.

Do you understand why starting count (which you could rename to guesses_left) is a slightly more logic approach? This way, we don’t have to do math when we want to print the number of remaining guesses

what if I put something before that like:
I chose a number for 0 to 9, I want you to guess it.
You have three tries to guess the number
1st guess: 5
Sorry your guess is wrong but I’ll give you a hint
My number is greater than your guess

Something like that uh hehe i’ll try to google something like that

you could use if and else to determine if guess is greater then random_number, else is must be smaller, so then you can inform the user

its a basic if/else, if you are a bit familiar with programming and or python, this should be a piece of cake.

:joy: thanks very much

Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type “copyright”, “credits” or “license()” for more information.

from random import randrange
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess ==random_number:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
if guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax

What’s wrong with this?

Please format your code properly:

How do I format code in my posts?

or:

How do I format code in my posts?

come on, look at what you posted. Its really difficult to read

'Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type “copyright”, “credits” or “license()” for more information.

from random import randrange
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess ==random_number:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
if guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
elif guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax

‘’'
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)] on win32
Type “copyright”, “credits” or “license()” for more information.

from random import randrange
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess ==random_number:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
if guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax

def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
elif guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax

‘’’

Is it really that difficult? here:

else guess > random_number:

else can’t have a condition since its everything else (all remaining scenarios), by setting a condition you might get unhandled scenarios

one version of your code should be enough?

wait hehe i don’t know how

I provided two topics which explain formatting code. Please figure it out before i help you any further.

from random import randrange
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess ==random_number:

SyntaxError: invalid syntax
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:

SyntaxError: invalid syntax
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
if guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:

SyntaxError: invalid syntax
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
if guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
guess = int(raw_input("Enter a guess: "))
if guess == random_number:
print 'Congratulations! You win!'
break
elif guess < random_number:
count -= 1
print 'Sorry your guess is too low.You have ‘+str(2-count)+’ guesses left’
else guess > random_number:
count -= 1
print 'Sorry your guess is too high.You have ‘+str(2-count)+’ guesses left’
else:
print 'Sorry, you ran out of chances. The number is ’ + str(random_number)

SyntaxError: invalid syntax

your code:

from random import randrange
def start_guess():
random_number=randrange(0,9)
print(“I chose a number for 0 to 9, I want you to guess it.”)
while count < 3:
try:
guess = int(raw_input("Enter a guess: "))
if guess ==random_number:

vs formatted code:

 from random import randrange
 def start_guess():
	random_number=randrange(0,9)
	print("I chose a number for 0 to 9, I want you to guess it.")
	while count < 3:
		try:
			guess = int(raw_input("Enter a guess: "))
		if guess ==random_number:

quite a difference, no?

Also, just post one version of your code. I can help you, but i am not going to explain everything you try and discard that doesn’t work.

>>> from random import randrange
>>> def start_guess():
	random_number=randrange(0,9)
	print("I chose a number for 0 to 9, I want you to guess it.")
	while count < 3:
		guess = int(raw_input("Enter a guess: "))
		if guess == random_number:
			print 'Congratulations! You win!'
			break
		elif guess < random_number:
			count -= 1
			print 'Sorry your guess is too low.You have '+str(2-count)+' guesses left'
		else guess > random_number:
			count -= 1
			print 'Sorry your guess is too high.You have '+str(2-count)+' guesses left'
else:
	print 'Sorry, you ran out of chances. The number is ' + str(random_number)
	
SyntaxError: invalid syntax
>>> 

i already covered why you get an invalid syntax error

oh ok ! thanks for the help!!!

should i put elif instead of else?

Why? Are there any other scenarios left then?

Let me be honest, i am fine with you doing a trial and error approach, but don’t come to me for every trail which isn’t working. I already helped you a lot