This was my "Guessing game", before checking the way you did it :D secret_word = "giraffe" guess = "" attempt = 3 while guess != secret_word and attempt >= 1: attempt -= 1 guess = input("Enter guess: ") if attempt == 1: print("You still have " + str(attempt) + " attept") elif attempt == 0: print("You have no more attempts!") else: print("You still have " + str(attempt) + " attepts") if guess == secret_word: print("You win!") else: print("You lose!")
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement. secretWord = "python" guess = "" guessCount = 0 while guess != secretWord: if guessCount == 3: break else: guess = input("Enter a guess: ") guessCount += 1 if guess == secretWord: print("You Win!") else: print("You Loose!")
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement. secretWord = "python" guess = "" guessCount = 0 while guess != secretWord: if guessCount == 3: break else: guess = input("Enter a guess: ") guessCount += 1 if guess == secretWord: print("You Win!") else: print("You Loose!")
Just used this video as an example of the best way to teach code to beginners. My course has all the abstract ideas (variables, iteration, etc.) followed by examples. IMO, that's an arse-about way to teach coding. My course content was so confusing I came to RUclips ...so glad to find your channel 😍
My way of doing word = "Guess" guess_word = "" limit = 3 while word != guess_word and limit != 0: guess_word = input("Enter word : ") limit -= 1 if word == guess_word: print("You win") else: print("You Lose")
Write a program in Python for the following numerical game with additional features: The computer stores a random number between 1 and 100. The player (user) attempts to guess the number. The player has a total of five attempts. After each wrong guess, the computer tells the user if the number was too high or too low. If the fifth attempt is also wrong, the number is output on screen. The player wins if he or she can guess the number within five attempts. The player is allowed to repeat the game as often as he or she wants. Track the number of games played and the number of wins. Provide an option to view the game statistics (number of games played, number of wins, and win percentage). Implement input validation to ensure the user enters a valid number within the specified range. Use object-oriented principles: Create classes for the game logic, player statistics, and user interface. Add exception handling to manage unexpected errors who can finish this code?
My Guessing game code word = "refer" guess = "" guess_number = 0 guess_limit = 5 while guess != word and guess_number < guess_limit: guess = input("Enter the word: ") guess_number += 1 if guess != word: print("Try again!") if guess == word: print("You guessed the word!") else: print("You failed!")
using this guy's vid for understanding the language since I knew C from my school. Really he deserves to be known! I made this simplified version with less variables but with a break. Check it out ^_^ secret_word = "Giraffe" guess = "" guess_count = 0 while guess != secret_word: if guess_count
import random x= random.randrange(o,15) list= "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15" print(list) n=int(input('insere um número entre 0-15':)) while n!= x: print("errado! tente de novo") if x>n: print('adivinha um número maior') n=int(input('Insere outro número')) else: print('adivinha um número maior') n=int(input(Insere outro número' )) print('Está certo!') ~
I eneded up with a compact version of the code lemme know if it has any flows. Thank you secret_word = "Giraffe" guess = "" tries = 0 while secret_word != guess and tries < 3: guess = input("Please type your guess: ") tries += 1 if tries == 3 : print("You run out of chances") elif guess == secret_word: print("You won ")
Fantastic tutorial! Is there a reason for why you use the variable "guess_limit" instead of just 3? Then you would just need to write "if guess_count < 3" instead of "if guess_count < guess_limit"
Here is my code in which i made a list of words and made a function to chose randomly, also has a scoring system. Any feedback would be helpful thanks import random words = ['ant', 'bee', 'cat', 'dog', 'egg', 'hat', 'golf', 'jelly', 'king', 'bird', 'hot', 'cold', 'fish', 'log', 'dad', 'mum', 'goal', 'help', 'frog', 'neat', 'car', 'moon', 'eye', 'tree', 'rice', 'ice', 'speed', 'rat', 'water', 'rain', 'snow', 'spoon', 'light', 'gold', 'zoo', 'oil', 'goat', 'yoga', 'judo', 'japan', 'hello', 'train', 'star', 'start', 'fork', 'teri', 'kevin', 'booker', 'deny', 'dojo', 'code', 'dodge', 'honey'] def choose_random_word(lst): # chooses a word then removes it from the list, to avoid repetition w = random.randrange(len(lst)) return lst.pop(w) def main_loop(): global player_score pick = choose_random_word(words) character_length = len(pick) print(" Round {} - score:{}".format(i, player_score)) print("The word has {} characters".format(character_length)) first_letter = pick[0] last_letter = pick[-1] print("The first letter is {}".format(first_letter.upper())) answer = input("\tEnter your answer: ") tries_count = 3 if answer == pick: print("\tGreat first try! 5 points") player_score += 5 else: print("The last letter is {}".format(last_letter)) while answer != pick and tries_count >= 0: answer = input("Please try again, you have {} tries left: ".format(tries_count)) tries_count -= 1 if character_length > 3: print("Letter {} is {}".format((tries_count+1), pick[tries_count])) if answer == pick: print("good 1 point") player_score += 1 if answer != pick and tries_count < 0: print("\tIncorrect. The correct word was {}".format(pick)) if player_score > 0: player_score -= 1 def print_score(): print("
Your total score was {}".format(player_score)) player_score = 0 times_to_play = 10 for i in range(1, 1 + times_to_play): main_loop() times_to_play += 1 print_score()
here is my version: secret_word = "carrot" guess = "" attempt = 3 hint = "" yes = "yes" while guess != secret_word and attempt >= 1: attempt -= 1 guess = input("Enter guess: ") if attempt == 1: print("You still have " + str(attempt) + " attempt") hint = input("Do you want a hint? ") if hint == yes: print("it is a vegetable") else: print("okay") elif attempt == 0: print("You have no more attempts!") else: print("You still have " + str(attempt) + " attempts") hint = input("Do you want a hint? ") if hint == yes: print("it is orange in color") else: print("okay") if guess == secret_word: print("You win!") else: print("You lose!")
My way of doing it: secret_word = "pyhton" guess = "" guess_count = 0 print("Welcome to our guessing game!") print("Enter a word and see if you guessed the secret one: ") while guess != secret_word and guess_count < 3: guess = input("Enter your guess: ") guess_count += 1 if guess == secret_word: print("That's right! You win.") else: print("Out of guesses! You lose.")
Same question. But I found something more understandable code for this that do not require variable "guess". Here it is: secret_word = "Giraffe" guess_count = 0 guess_limit = 3 while guess_count < guess_limit: guess = input("Guess: ") guess_count += 1 if guess == secret_word: print ("You won!) break else: print("You lose..")
I think, otherwise python will throw an error when guess is used as the condition after the While statement. Either because the variable needs to be defined first or because it needs to have some sort of value to be used. It's empty because the value will be redefined by Input in the loop anyway, so it doesn't matter what it contains at first.
I got the code correct but my problem is, the phrase 'You won!' keeps appearing even without getting the secret word correct but after getting it correct it appears then no more options just like yours Sir. What binding am I missing
I added a feature that asks the user whether they want to continue or quit when they get the wrong answer to this program and the user can respond by typing "y" or "n" for yes or no. Code below. word = "Giraf" guess = "" guess_count = 0 guess_limit = 2 out_of_guesses = False while guess != word and not out_of_guesses: if guess_count < guess_limit: guess = input("What's the word? ") guess_count += 1 else: out_of_guesses = True print("You lose.") break if guess == "giraf": print("You win!") break else: question = input("Do it again?") if question == 'y': print("One more try!") pass elif question == 'n': print("Okay. Goodbye.") break else: print("Invalid input.") Please let me know if anyone sees any flaws in the code. One possible flaw that I see that might come up is it asking me even when the user is out of guess chances.
Chiming in here in 2020 using Python 3.3 and I'm getting an error using the "input("Enter a guess: ")". I was only able to get the program to work if I used raw_input vs just input
I was not able understand your tutorial fully and i made my own code. But i guess something is wrong, can anyone tell where can i improve secret_word = "Ligma" guess = "" guess_count = 0 guess_limit = 4 while secret_word != guess: guess_count += 1 if guess_count < guess_limit: guess = input("Enter your guess: ") elif guess_count == guess_limit: print("Out of guesses you lose.") if guess == secret_word: print("You win")
See this guys, I made it in more simple way : # simple guessing game : sec_word = "apple" # secret word chance_left = 3 # chance left for user user_guess = "" # user's guess word while sec_word != user_guess and chance_left != 0: print(">") user_guess = input("Enter your guess word : ") chance_left -= 1 if sec_word == user_guess: print("You are correct, Congratulation You won!") else: print("Finished chance, Sorry you lose! ")
Could someone explain why there had to be a global variable for guess with empty quotes. Would it have worked the same if the only variable for guess was the input inside of the whole loop?
That would not work, as the while loop checks for the guess variable before it is even declared inside the loop. Since the while loop comes before, declaring the variable only inside would give you an error, as the variable does not yet exist.
Ask the user a question. Read his answer and check if his answer is right or not. If right, say the answer is right. If wrong, prompt him to guess again. He can guess a maximum of 5 times. Before the last guess, give him a “last guess” warning. If he cannot guess within 5 times, display that he/she . can anyone please solve this question?
My way of doing it :) : password = "Aladdin" answer = "" answer_limit = 3 answer_count = 0 while answer != password and answer_count < answer_limit: answer = input ("Enter your password: ") answer_count += 1 if answer == password: print ("Authorized!") else: print("You are not authorized!")
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement. secretWord = "python" guess = "" guessCount = 0 while guess != secretWord: if guessCount == 3: break else: guess = input("Enter a guess: ") guessCount += 1 if guess == secretWord: print("You Win!") else: print("You Loose!")
Can anyone tell me what should we enter in the guess variable if we want to allow them to enter a number instead of a string . I mean we need to put "" even for numbers or anything else 🤔🤔 I'M REALLY NEW TO THIS!😅😅😅
Can't resolve the endless loop. it keeps asking "Would you like to play again?" Yes or No is not working properly import random as rd play = True while play: number = rd.randint(1, 20) guess = int(input("Guess a number between 1 and 20: ")) count = 0 while count < guess != number: count +=1 if guess > number: print(guess, "was too high. Try again.") if guess < number: print(guess, "was too low. Try again.") guess = int(input("Guess again!")) print(guess, "was the number! You win!", "well done in ", count, "tries")
while True: answer = input('Would you like to play again?: ').lower()
if answer == 'Yes': play = True continue # break elif answer == 'No': break else: answer = input('Incorrect option. Type "Yes" to try again or "No" to leave the game').lower()
import random as rd def main_game(): play = True while play: number = rd.randint(1, 20) guess = int(input("Guess a number between 1 and 20: ")) count = 0 while count < guess != number: count += 1 if guess > number: print(guess, "was too high. Try again.") if guess < number: print(guess, "was too low. Try again.") guess = int(input("Guess again! ")) print(guess, "was the number! You win!", "well done in", count, "tries") play = False main_game() play_again = True while play_again: answer = input('Would you like to play again?: ').lower() if answer == 'yes': main_game() elif answer == 'no': quit() else: answer = input('Incorrect option. Type "Yes" to try again or "No" to leave the game: ').lower() ------------------------ Im sure there is a better solution but at least it works now :P
@@kevinnisbet5648 One more thing, play the game, and instead of typing a guess number, type yes or no, code breaks. Also when the game ends, type in a number instead of yes or no to end the game, and it is still not accepting Yes or no 16 was the number! You win! well done in 6 tries Would you like to play again?: yes Incorrect option. Type "Yes" to try again or "No" to leave the gameYes Would you like to play again?: Yes Incorrect option. Type "Yes" to try again or "No" to leave the game Let's keep trying :)
@@oceansblue692 for me the guessing is ok. Guess a number between 1 and 20: 10 10 was too low. Try again. Guess again! 15 15 was the number! You win! well done in 1 tries Would you like to play again?: yes Guess a number between 1 and 20: For me it works fine, if the input is fine. BUT if the code expects a int (number) and gets a char or a string it will cause an error, try using a try/except clause ** also after looking at this maybe start the tries from 1, it took me 2 tries but still says 1 tries. Also maybe use an if statement, if tries < 1 use try else tries .... if that makes sense?
@@kevinnisbet5648 Makes sense. Except that i am not that good yet. "using a try/except clause" never used. "an if statement, if tries < 1 use try else tries" Will keep trying. Thanks!
What's the use of , guess=" " , you said it's to store all guesses . What does that mean? is it only in things with user input? because we haven't done this in the former videos that had user input(mad lib game).
I will never win a guess like this as I have never got a clue to answer to the game either guess the name of a wild animal or a tall animal in the world. Just give the user a lead.
This was my "Guessing game", before checking the way you did it :D
secret_word = "giraffe"
guess = ""
attempt = 3
while guess != secret_word and attempt >= 1:
attempt -= 1
guess = input("Enter guess: ")
if attempt == 1:
print("You still have " + str(attempt) + " attept")
elif attempt == 0:
print("You have no more attempts!")
else:
print("You still have " + str(attempt) + " attepts")
if guess == secret_word:
print("You win!")
else:
print("You lose!")
wrong
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement.
secretWord = "python"
guess = ""
guessCount = 0
while guess != secretWord:
if guessCount == 3:
break
else:
guess = input("Enter a guess: ")
guessCount += 1
if guess == secretWord:
print("You Win!")
else:
print("You Loose!")
Too long process
Check this out:
secret_word = "Giraffe"
guess = ""
guess_count = 0
while guess != secret_word:
if guess_count
@@Ryan_Parmelee 4
I loved this tutorial! I spent a lot of time adding extra functions to my guessing game and expanding this! thank you!
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement.
secretWord = "python"
guess = ""
guessCount = 0
while guess != secretWord:
if guessCount == 3:
break
else:
guess = input("Enter a guess: ")
guessCount += 1
if guess == secretWord:
print("You Win!")
else:
print("You Loose!")
Check this out:
secret_word = "Giraffe"
guess = ""
guess_count = 0
while guess != secret_word:
if guess_count
your spelling of "lose" is wrong cuz what you spelt means the opposite of "tight"
lol jk i know its an error anyway nice code
This really helped
Thanks
This was my guessing game before watching his brilliant idea....
sw = "Insane"
guess = ""
attempt = 3
print("Hint :- Gopal")
while guess != sw and attempt > 0:
print("You have", attempt, "attempts left")
guess = input("Enter your guess: ")
attempt -= 1
if guess != sw:
if attempt < 1:
print("You lose")
elif attempt > 1:
print("try harder")
elif guess == sw:
print("Well Done")
Just used this video as an example of the best way to teach code to beginners.
My course has all the abstract ideas (variables, iteration, etc.) followed by examples.
IMO, that's an arse-about way to teach coding. My course content was so confusing I came to RUclips ...so glad to find your channel 😍
The second review was very helpful. Thanks!
My way of doing
word = "Guess"
guess_word = ""
limit = 3
while word != guess_word and limit != 0:
guess_word = input("Enter word : ")
limit -= 1
if word == guess_word:
print("You win")
else:
print("You Lose")
make it simple,
secret_word = "giraffe"
guess = ""
guess_count = 0
while guess != secret_word and guess_count < 3:
guess = input("Enter a guess: ")
guess_count += 1
if guess != secret_word:
print("You lose!")
else:
print("You win!")
Write a program in Python for the following numerical game with additional features:
The computer stores a random number between 1 and 100.
The player (user) attempts to guess the number.
The player has a total of five attempts.
After each wrong guess, the computer tells the user if the number was too high or too
low.
If the fifth attempt is also wrong, the number is output on screen.
The player wins if he or she can guess the number within five attempts.
The player is allowed to repeat the game as often as he or she wants.
Track the number of games played and the number of wins.
Provide an option to view the game statistics (number of games played, number of wins,
and win percentage).
Implement input validation to ensure the user enters a valid number within the specified
range.
Use object-oriented principles: Create classes for the game logic, player statistics, and
user interface.
Add exception handling to manage unexpected errors
who can finish this code?
My Guessing game code
word = "refer"
guess = ""
guess_number = 0
guess_limit = 5
while guess != word and guess_number < guess_limit:
guess = input("Enter the word: ")
guess_number += 1
if guess != word:
print("Try again!")
if guess == word:
print("You guessed the word!")
else:
print("You failed!")
using this guy's vid for understanding the language since I knew C from my school. Really he deserves to be known!
I made this simplified version with less variables but with a break. Check it out ^_^
secret_word = "Giraffe"
guess = ""
guess_count = 0
while guess != secret_word:
if guess_count
awesome
Kudos... like how you've simplified. Mike's example explains the concepts better.
secret_word="Test"
guess=""
trynumber=0
while guess!=secret_word :
guess=input("Enter Guess : ")
#print("try again")
trynumber += 1
if trynumber>=3:
#print("break")
break
if trynumber>=2 and guess!=secret_word:
print("Your limit crossed")
if guess==secret_word :
print("You win ")
Congrats on 100 k subscribers !🎉
This is REALLY GOOD!! You explain really well. Thank you!
import random
x= random.randrange(o,15)
list= "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"
print(list)
n=int(input('insere um número entre 0-15':))
while n!= x:
print("errado! tente de novo")
if x>n:
print('adivinha um número maior')
n=int(input('Insere outro número'))
else:
print('adivinha um número maior')
n=int(input(Insere outro número' ))
print('Está certo!')
~
I eneded up with a compact version of the code lemme know if it has any flows. Thank you
secret_word = "Giraffe"
guess = ""
tries = 0
while secret_word != guess and tries < 3:
guess = input("Please type your guess: ")
tries += 1
if tries == 3 :
print("You run out of chances")
elif guess == secret_word:
print("You won ")
Guessing Game
(before i watch the video)
secret_number = 7
guess = ""
count = 0
while secret_number != guess and count != 5:
guess = int(input("Enter the Guess : "))
count += 1
if count == 5:
print("You fail!")
else:
print("you win!")
hell yeah..I got my code right..... thanks so much Mike.
thank you, your video saved me from a probleam.
Fantastic tutorial! Is there a reason for why you use the variable "guess_limit" instead of just 3? Then you would just need to write "if guess_count < 3" instead of "if guess_count < guess_limit"
2 years late but i think its simply just to make the script more readable
Here is my code in which i made a list of words and made a function to chose randomly, also has a scoring system.
Any feedback would be helpful thanks
import random
words = ['ant', 'bee', 'cat', 'dog', 'egg', 'hat', 'golf', 'jelly', 'king', 'bird', 'hot', 'cold', 'fish', 'log',
'dad', 'mum', 'goal', 'help', 'frog', 'neat', 'car', 'moon', 'eye', 'tree', 'rice', 'ice', 'speed', 'rat',
'water', 'rain', 'snow', 'spoon', 'light', 'gold', 'zoo', 'oil', 'goat', 'yoga', 'judo', 'japan', 'hello',
'train', 'star', 'start', 'fork', 'teri', 'kevin', 'booker', 'deny', 'dojo', 'code', 'dodge', 'honey']
def choose_random_word(lst): # chooses a word then removes it from the list, to avoid repetition
w = random.randrange(len(lst))
return lst.pop(w)
def main_loop():
global player_score
pick = choose_random_word(words)
character_length = len(pick)
print("
Round {} - score:{}".format(i, player_score))
print("The word has {} characters".format(character_length))
first_letter = pick[0]
last_letter = pick[-1]
print("The first letter is {}".format(first_letter.upper()))
answer = input("\tEnter your answer: ")
tries_count = 3
if answer == pick:
print("\tGreat first try! 5 points")
player_score += 5
else:
print("The last letter is {}".format(last_letter))
while answer != pick and tries_count >= 0:
answer = input("Please try again, you have {} tries left: ".format(tries_count))
tries_count -= 1
if character_length > 3:
print("Letter {} is {}".format((tries_count+1), pick[tries_count]))
if answer == pick:
print("good 1 point")
player_score += 1
if answer != pick and tries_count < 0:
print("\tIncorrect. The correct word was {}".format(pick))
if player_score > 0:
player_score -= 1
def print_score():
print("
Your total score was {}".format(player_score))
player_score = 0
times_to_play = 10
for i in range(1, 1 + times_to_play):
main_loop()
times_to_play += 1
print_score()
Your Code is epic & educational. Thanks for sharing.
Do you think you can look at my code?
@@oceansblue692 Thanks! Sure send it across
@@kevinnisbet5648 I did share it in the comments, if you scroll up, you will find it.
Much appreciated.
@@oceansblue692 Ok, please check,
here is my version:
secret_word = "carrot"
guess = ""
attempt = 3
hint = ""
yes = "yes"
while guess != secret_word and attempt >= 1:
attempt -= 1
guess = input("Enter guess: ")
if attempt == 1:
print("You still have " + str(attempt) + " attempt")
hint = input("Do you want a hint? ")
if hint == yes:
print("it is a vegetable")
else:
print("okay")
elif attempt == 0:
print("You have no more attempts!")
else:
print("You still have " + str(attempt) + " attempts")
hint = input("Do you want a hint? ")
if hint == yes:
print("it is orange in color")
else:
print("okay")
if guess == secret_word:
print("You win!")
else:
print("You lose!")
Like your videos the most👏👏
The way u teach is amazing n helpful 🙌
and it is my opinion:
secret_word = "giraffe"
guess = ""
tries = 3
while guess != secret_word:
guess = input("Enter secret word: ")
tries -= 1
if tries == 0:
print("you lose")
break
print("you win")
i think you missed "else:" before the "print("you win")"?
@@JackEacher yes you are true
I appreciate you a lot you made it easy to get it right for me.
secret_word="Test"
guess=""
trynumber=0
while guess!=secret_word :
guess=input("Enter Guess : ")
trynumber += 1
if guess!=secret_word:
print("You have :" , abs(trynumber-2),"Guess left")
#trynumber += 1
if trynumber>=3:
#print("break")
break
if trynumber>=2 and guess!=secret_word:
print("Your limit crossed")
if guess==secret_word :
print("You win ")
secret = "giraffe"
guess = ""
guess_limit = 3
while guess != secret and guess_limit > 0 :
guess = input("Enter guess")
guess_limit -=1
if guess == secret:
print("You win.")
else:
print("You lose.")
My way of doing it:
secret_word = "pyhton"
guess = ""
guess_count = 0
print("Welcome to our guessing game!")
print("Enter a word and see if you guessed the secret one: ")
while guess != secret_word and guess_count < 3:
guess = input("Enter your guess: ")
guess_count += 1
if guess == secret_word:
print("That's right! You win.")
else:
print("Out of guesses! You lose.")
This channel is good ilove it!
My assignment for class says I have to use for statements. not while loops
Why do we need to set the guess=""? And why is it blank?
Same question. But I found something more understandable code for this that do not require variable "guess".
Here it is:
secret_word = "Giraffe"
guess_count = 0
guess_limit = 3
while guess_count < guess_limit:
guess = input("Guess: ")
guess_count += 1
if guess == secret_word:
print ("You won!)
break
else:
print("You lose..")
@@Al-he6bs i think you just removed the guess variable
I think, otherwise python will throw an error when guess is used as the condition after the While statement.
Either because the variable needs to be defined first or because it needs to have some sort of value to be used.
It's empty because the value will be redefined by Input in the loop anyway, so it doesn't matter what it contains at first.
I got the code correct but my problem is, the phrase 'You won!' keeps appearing even without getting the secret word correct but after getting it correct it appears then no more options just like yours Sir. What binding am I missing
Can you post your code here? I'd like to see.
Thank . I just need to see how to do the loop and break thing
instead of the guessing game, password entering may be a better example")....
I added a feature that asks the user whether they want to continue or quit when they get the wrong answer to this program and the user can respond by typing "y" or "n" for yes or no.
Code below.
word = "Giraf"
guess = ""
guess_count = 0
guess_limit = 2
out_of_guesses = False
while guess != word and not out_of_guesses:
if guess_count < guess_limit:
guess = input("What's the word? ")
guess_count += 1
else:
out_of_guesses = True
print("You lose.")
break
if guess == "giraf":
print("You win!")
break
else:
question = input("Do it again?")
if question == 'y':
print("One more try!")
pass
elif question == 'n':
print("Okay. Goodbye.")
break
else:
print("Invalid input.")
Please let me know if anyone sees any flaws in the code.
One possible flaw that I see that might come up is it asking me even when the user is out of guess chances.
#"try again" statement included
password=""
guess_count=0
guess_limit=5
secret_word="hello"
while password!=secret_word and guess_count
Chiming in here in 2020 using Python 3.3 and I'm getting an error using the "input("Enter a guess: ")". I was only able to get the program to work if I used raw_input vs just input
Try this: ruclips.net/video/B161emPL2hg/видео.html
Thanks like your videos they help me a lot and you explain it so good
thanks for da code now i found my wae of programming :D
I was not able understand your tutorial fully and i made my own code. But i guess something is wrong, can anyone tell where can i improve
secret_word = "Ligma"
guess = ""
guess_count = 0
guess_limit = 4
while secret_word != guess:
guess_count += 1
if guess_count < guess_limit:
guess = input("Enter your guess: ")
elif guess_count == guess_limit:
print("Out of guesses you lose.")
if guess == secret_word:
print("You win")
tried my own before watching the code was functional :
no_of_attempts=1
guess_word =""
while no_of_attempts
what if u wanted the guess word to be more than one word or number?
thanks, sir!
Much appreciated !!!
Good vid, learnt alot
After writing the program, i tried to write down my secret word but need to type it down three times in order for me to "win". why is this so?
I would love to help, but I'd need to see your code for that
See this guys, I made it in more simple way :
# simple guessing game :
sec_word = "apple" # secret word
chance_left = 3 # chance left for user
user_guess = "" # user's guess word
while sec_word != user_guess and chance_left != 0:
print(">")
user_guess = input("Enter your guess word : ")
chance_left -= 1
if sec_word == user_guess:
print("You are correct, Congratulation You won!")
else:
print("Finished chance, Sorry you lose! ")
hello uh, what software are you using?
For python? Pycharm
how to answer guess the secret number have six digit code 0-999999, do you have some trick, help please
is there any loop like while not in python
while not True
while False
while 1 == 2
Can someone tell me why we use booleans here?
Could someone explain why there had to be a global variable for guess with empty quotes. Would it have worked the same if the only variable for guess was the input inside of the whole loop?
That would not work, as the while loop checks for the guess variable before it is even declared inside the loop. Since the while loop comes before, declaring the variable only inside would give you an error, as the variable does not yet exist.
@@penta5421 Thank you sir
@@typeterson8376 No problem!
Ask the user a question. Read his answer and check if his answer is right or not. If right, say the answer is right. If wrong, prompt him to guess again. He can guess a maximum of 5 times. Before the last guess, give him a “last guess” warning. If he cannot guess within 5 times, display that he/she . can anyone please solve this question?
secret_word = "cat"
guess = ""
guess_limit = 5
guesses = 0
while guess != secret_word:
if guesses < guess_limit:
guess = input("Enter a guess: ")
guesses += 1
if guesses == 4:
guess = input("LAST GUESS! Enter guess: ")
guesses += 1
if guess == secret_word:
print ("YOU WIN")
break
else:
print ("YOU LOSE")
break
My way of doing it :) :
password = "Aladdin"
answer = ""
answer_limit = 3
answer_count = 0
while answer != password and answer_count < answer_limit:
answer = input ("Enter your password: ")
answer_count += 1
if answer == password:
print ("Authorized!")
else:
print("You are not authorized!")
what about if you want to set multiple passwords ?
Here's how I did it. I simplified the code while still maintaining the same functionality. The only difference is I had to use the "break" statement.
secretWord = "python"
guess = ""
guessCount = 0
while guess != secretWord:
if guessCount == 3:
break
else:
guess = input("Enter a guess: ")
guessCount += 1
if guess == secretWord:
print("You Win!")
else:
print("You Loose!")
Can anyone tell me what should we enter in the guess variable if we want to allow them to enter a number instead of a string . I mean we need to put "" even for numbers or anything else 🤔🤔
I'M REALLY NEW TO THIS!😅😅😅
Int(input(enter a number plz!))
Another way to write/
N= Input(“Enter a number”)
Int(n)
So the int() function is to convert a string to a integer
@@CK-bu5wh Thank you !🙃
Hi Mike,
In case if the secret_word/title is a book title with more than one word,
how to search for a word or few letters using the while loop.
Can't resolve the endless loop. it keeps asking "Would you like to play again?" Yes or No is not working properly
import random as rd
play = True
while play:
number = rd.randint(1, 20)
guess = int(input("Guess a number between 1 and 20: "))
count = 0
while count < guess != number:
count +=1
if guess > number:
print(guess, "was too high. Try again.")
if guess < number:
print(guess, "was too low. Try again.")
guess = int(input("Guess again!"))
print(guess, "was the number! You win!", "well done in ", count, "tries")
while True:
answer = input('Would you like to play again?: ').lower()
if answer == 'Yes':
play = True
continue # break
elif answer == 'No':
break
else:
answer = input('Incorrect option. Type "Yes" to try again or "No" to leave the game').lower()
import random as rd
def main_game():
play = True
while play:
number = rd.randint(1, 20)
guess = int(input("Guess a number between 1 and 20: "))
count = 0
while count < guess != number:
count += 1
if guess > number:
print(guess, "was too high. Try again.")
if guess < number:
print(guess, "was too low. Try again.")
guess = int(input("Guess again! "))
print(guess, "was the number! You win!", "well done in", count, "tries")
play = False
main_game()
play_again = True
while play_again:
answer = input('Would you like to play again?: ').lower()
if answer == 'yes':
main_game()
elif answer == 'no':
quit()
else:
answer = input('Incorrect option. Type "Yes" to try again or "No" to leave the game: ').lower()
------------------------
Im sure there is a better solution but at least it works now :P
@@kevinnisbet5648 Brilliant!
@@kevinnisbet5648 One more thing, play the game, and instead of typing a guess number, type yes or no, code breaks.
Also when the game ends, type in a number instead of yes or no to end the game,
and it is still not accepting Yes or no
16 was the number! You win! well done in 6 tries
Would you like to play again?: yes
Incorrect option. Type "Yes" to try again or "No" to leave the gameYes
Would you like to play again?: Yes
Incorrect option. Type "Yes" to try again or "No" to leave the game
Let's keep trying :)
@@oceansblue692 for me the guessing is ok.
Guess a number between 1 and 20: 10
10 was too low. Try again.
Guess again! 15
15 was the number! You win! well done in 1 tries
Would you like to play again?: yes
Guess a number between 1 and 20:
For me it works fine, if the input is fine.
BUT if the code expects a int (number) and gets a char or a string it will cause an error, try using a try/except clause
** also after looking at this maybe start the tries from 1, it took me 2 tries but still says 1 tries. Also maybe use an if statement, if tries < 1 use try else tries .... if that makes sense?
@@kevinnisbet5648 Makes sense. Except that i am not that good yet.
"using a try/except clause" never used.
"an if statement, if tries < 1 use try else tries" Will keep trying.
Thanks!
you are very cool dude😎
Hi good one
🙏
It is not working in phone🥺🥺😣
What's the use of , guess=" " , you said it's to store all guesses . What does that mean? is it only in things with user input? because we haven't done this in the former videos that had user input(mad lib game).
use a list
sick..
I tried different code. Pls let me know, any flaws in it.
secret_word2 = "Surprise"
guess1 = ""
guess_count = 0
while guess1 != secret_word2 and guess_count < 3 :
guess1 = input("Enter guess: ")
guess_count += 1
if guess1 == secret_word2 :
print ("You win!")
elif guess_count < 3 :
print("Try again")
else :
print ("You lose!")
legend
I will never win a guess like this as I have never got a clue to answer to the game either guess the name of a wild animal or a tall animal in the world. Just give the user a lead.