I believe i have highlighted the sections i'm referring to below.
So i just want to understand the parts i'm going to ask about, because i got confused and don't want to move onto the next section until i understand them.
line 18 - 22,
i understand that name and system, the net is for windows and clr is to clear the screen and the else is there in case it is mac or something else, so either way it clears the screen, so is that the main reason for this function, that is clears my screen after typing information and then whatever need to be retained stays on the appropriate section of the screen?
line 45,
the function there that has (good, bad) for arguments, what does good and bad do, i'm confused with how arguments work honestly. So here couldn't that part of code have been written without them or did it need them to write the code?
then line 58,
what does return guess do ? Couldn't we have done print guess? I'm still trying to understand how return works as well.
then line 71,
what in the world is found = True for? I'm very confused here, as well as line 74 where found is now false? Then line 75 where, if found: what does this mean? that whole part of code from line 71 to 75 has me lost.
then line 83
where done = true and that is the argument to the play function? What does that do? then line 89 where return makes done = false? Return runs the play function and makes the argument false??? how did we run the function through return that also confuses me?
then line 99
what does return true do there? Why is it there?
then lastly what does 103
done = False do, how did done go from true to false and what did it do each time?
I really appreciate any help here, I understand most the code but i feel this will really help me get clarity.
THANK YOU ALL FOR THE HELP SO MUCH THANK YOU!!!
So i just want to understand the parts i'm going to ask about, because i got confused and don't want to move onto the next section until i understand them.
line 18 - 22,
i understand that name and system, the net is for windows and clr is to clear the screen and the else is there in case it is mac or something else, so either way it clears the screen, so is that the main reason for this function, that is clears my screen after typing information and then whatever need to be retained stays on the appropriate section of the screen?
line 45,
the function there that has (good, bad) for arguments, what does good and bad do, i'm confused with how arguments work honestly. So here couldn't that part of code have been written without them or did it need them to write the code?
then line 58,
what does return guess do ? Couldn't we have done print guess? I'm still trying to understand how return works as well.
then line 71,
what in the world is found = True for? I'm very confused here, as well as line 74 where found is now false? Then line 75 where, if found: what does this mean? that whole part of code from line 71 to 75 has me lost.
then line 83
where done = true and that is the argument to the play function? What does that do? then line 89 where return makes done = false? Return runs the play function and makes the argument false??? how did we run the function through return that also confuses me?
then line 99
what does return true do there? Why is it there?
then lastly what does 103
done = False do, how did done go from true to false and what did it do each time?
I really appreciate any help here, I understand most the code but i feel this will really help me get clarity.
THANK YOU ALL FOR THE HELP SO MUCH THANK YOU!!!
import random import os import sys words = [ 'apple', 'banana', 'orange', 'coconut', 'strawberry', 'lime', 'lemon', 'blueberry', 'melon', ] def clear(): if os.name == 'net': os.system('cls') else: os.system('clear')[ / color] def draw(bad, good, secret_word): clear() print('strikes: {}/7'.format(len(bad))) print('') for letter in bad: print(letter, end=' ') print('\n\n') for letter in secret_word: if letter in good: print(letter, end='') else: print('_', end='') print('') def get_guess(bad, good): while True: guess = input("guess a letter: ").lower() if len(guess) != 1: print("you can only guess a single letter") continue elif guess in bad or guess in good: print("you've already guessed that letter") continue elif not guess.isalpha(): print('you can only guess letters') continue else: return guess def play(done): clear() secret_word = random.choice(words) bad = [] good = [] while True: draw(bad, good, secret_word) guess = get_guess(bad, good) if guess in secret_word: good.append(guess) found = True for letter in secret_word: if letter not in good: found = False if found: print('win') print("word was {} ".format(secret_word)) else: bad.append(guess) if len(bad) == 7: draw(bad, good, secret_word) print('you lost secret word was{} '.format(secret_word)) done = True[ / color] if done: play_again = input('play again y/n') if play_again != 'n': else: sys.exit() def welcome(): start = input("press enter to start or q to quit ") if start == 'q': print('bye') sys.exit() else: return True[ / u][/color] print('welcome to letter guess') while True: clear() welcome() play(done)