Click here to Skip to main content
15,887,241 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Python
secret_number = 9
 guess_count = 0 
 guess_limit= 3
 while guess_count < guess_limit :
     Guess = int(input("Guess :  "))
     guess_count += 1
     if Guess == secret_number :
         print("YOU WON")
         break
 else:
     print("SORRY YOU FAILED")


What I have tried:

why ? guess_count += 1
and why? if Guess == secret_number :
and why? Guess = int(input("Guess") :
Posted
Updated 11-Jan-24 6:56am
v2

This says print "Guess" to the console, and wait for input. When something is typed in, try to convert it to an integer value and store the value in the varaible named Guess.
Python
Guess = int(input("Guess") :


This says add 1 to the variable named guess_count.
Python
guess_count += 1


And this one compares the two variables, and if they are equal it will execute the next indented statement(s). If they are not equal it will go to the else block.
Python
if Guess == secret_number :


See 3. An Informal Introduction to Python — Python 3.11.7 documentation[^].
 
Share this answer
 
Seriously, don't try to look at random code and "work out what it means" unless youy have a pretty good background in other languages - it won't help you to do anything.

If you want to know how code works, look at tutorials for the language - written ones, not youtube - and try the exercises they suggest. You will learn a lot more, a lot faster than asking "random questions" about really basic stuff!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900