Python Forum
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) "))
Reply
#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.
Reply
#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.
Reply
#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.
Reply
#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
Reply
#6
Thanks so much for all the help! Finally got it working! Big Grin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Absolute beginner am I missing something? kamren 7 482 Sep-25-2020, 05:32 AM
Last Post: buran
  chkFile with absolute paths JarredAwesome 7 401 Sep-21-2020, 03:51 AM
Last Post: bowlofred
  absolute imports between folders mikisDW 0 291 Aug-05-2020, 12:26 PM
Last Post: mikisDW
  I am an absolute newbie.Help me! feynarun 4 568 Apr-11-2020, 09:25 PM
Last Post: feynarun
  Absolute newbie asking for help with blinking LEDs misterfrickel 0 651 Mar-15-2019, 08:54 AM
Last Post: misterfrickel
  Absolute Beginner Python Question matchamochi7 5 1,484 Nov-02-2018, 12:09 PM
Last Post: wookie
  Problem with absolute path to file (Mr.Stickman Problems) SheeppOSU 3 2,469 Jun-26-2018, 10:05 AM
Last Post: Larz60+
  coding error from a script (absolute noob) fuchls 2 1,955 Jun-08-2018, 02:29 PM
Last Post: webrunner1981

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020