Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Absolute Beginner to Python
#1
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) "))
Quote
#2
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.
Quote
#3
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.
Quote
#4
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.
Quote
#5
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Absolute newbie asking for help with blinking LEDs misterfrickel 0 366 Mar-15-2019, 08:54 AM
Last Post: misterfrickel
  Absolute Beginner Python Question matchamochi7 5 979 Nov-02-2018, 12:09 PM
Last Post: wookie
  Problem with absolute path to file (Mr.Stickman Problems) SheeppOSU 3 1,445 Jun-26-2018, 10:05 AM
Last Post: Larz60+
  coding error from a script (absolute noob) fuchls 2 1,405 Jun-08-2018, 02:29 PM
Last Post: webrunner1981

Forum Jump:


Users browsing this thread: 1 Guest(s)