Python Forum
Absolute Beginner to Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Absolute Beginner to Python (/thread-13286.html)



Absolute Beginner to Python - dthomp54 - Oct-08-2018

I am an absolute beginner to python. I am learning through CodeHS. I cannot figure what I'm doing wrong with a particular assignment. It's the Guess the Secret Number assignment. I feel like I've done everything the way the sample says to do it, but it won't work. Please HELP!
speed(0)

secret_number = 7

def make_check(user_number):
    color("green")
    left(135)
    pensize(10)
    forward(30)
    backward(30)
    right(90)
    forward(60) 
  
user_number=int(input("What is the secret number? (1-10) "))

while user_number == secret_number:
    make_check(user_number)
    user_number=int(input("What is the secret number? (1-10) "))



RE: Absolute Beginner to Python - woooee - Oct-08-2018

Do some testing. What happens at this statement

while user_number == secret_number:
Again, do some testing.
print(user_number, secret_number)
while user_number == secret_number:
    print("within while")
Again, do some testing and find out.


RE: Absolute Beginner to Python - j.crater - Oct-08-2018

It would be very helpful if you explained what you want your code to do, and what exactly doesn't work as you expect it to. Without that, we can only give our best guess.

Function make_check() will only be called as long as user is guessing the number correctly. First time he guesses wrong, even if it is very first attempt, the script will end. You probably don't want such program logic, and in that case, just think of the order of how the operations are executed.
Also you pass user_number value to make_check(), but it is not used there.


RE: Absolute Beginner to Python - dthomp54 - Oct-08-2018

I'm very sorry for not explaining better.
The program is supposed to print a check mark on screen if a person selects the secret number.
Otherwise, it should ask for input again. I cannot get the while loop to work properly. Thanks for the help.


RE: Absolute Beginner to Python - ichabod801 - Oct-08-2018

Then the call to make_check should be after the loop, not in it. Also the while loop should go while they haven't guessed the correct answer. Currently it loops while they have guessed the correct answer.


RE: Absolute Beginner to Python - dthomp54 - Oct-09-2018

Thanks so much for all the help! Finally got it working! Big Grin