Python 3.5.1 Introduction to Python 2.1 Mark Clarkson - While Loop Issue -
i'm working way through set of tutorials. in section 3.2a - while loops following code supposed loop until user enters target number (7) display congratulations message regardless of number entered python either gives right answer or wrong answer, 7 flag wrong answer. know there other ways perform sort of task code tutorial working.
targetnumber = 7 guess = input("guess number between 1 , 10 ") while guess != targetnumber: print("wrong, try again ") guess = input("guess number between 1 , 10 ") print("congratulations - that's right!")
you should convert target numger string before comparison. also, should exclude congratulations message loop. suggest :
targetnumber = str(7) guess = input("guess number between 1 , 10 ") while guess != targetnumber: print("wrong, try again ") guess = input("guess number between 1 , 10 ") print("congratulations - that's right!")
the detail input returns string , if compare string integer, return false.
Comments
Post a Comment