On Apr 13, 2015, at 1:34 PM, Michael Havens <bmike1@gmail.com> wrote:Okay Jason, I did it your way. The resulting code being 2 lines shorter. Unfortunately I still have the same problem as before (that being if the guess is wrong it gives no suggestion as to higher/lower but rather just asks you to guess again):python 1-30guess.pyWelcome.Guess the number: 0Guess the number: 0Guess higher.Guess the number: 9Guess lower.Guess the number: 8Guess lower.Guess the number: 7Guess lower.Guess the number: 6Guess lower.Guess the number: 5Guess lower.Correct.here is the code:#!/usr/bin/env pythonprint("Welcome.")g = input("Guess the number: ")guess = int(g)while guess != 5:g = input("Guess the number: ")guess = int(g)if guess < 5:print("Guess higher.")else:print("Guess lower.")print("Correct.")---------------------------------------------------:-)~MIKE~(-:On Mon, Apr 13, 2015 at 12:48 PM, Sesso <sesso@djsesso.com> wrote:You may be better off using if statements.If number is less than 5print guess higherelseprint guess lowerThen wrap all of that in a while loop with a condition of while less than 5.JasonOn Apr 13, 2015, at 12:44 PM, Michael Havens <bmike1@gmail.com> wrote:however it does give suggestions on subsequent guesses....---------------------------------------------------:-)~MIKE~(-:On Mon, Apr 13, 2015 at 12:42 PM, Michael Havens <bmike1@gmail.com> wrote:here is what I have (that sorta works):print("Welcome.")g = input("Guess the number: ")guess = int(g)while guess < 5:g = input("Guess the number: ")guess = int(g)print("Guess higher.")while guess > 5:g = input("Guess the number: ")guess = int(g)print ("Guess lower.")print("Correct")What I mean by 'sorta' is if the first guess is not correct it does not give a suggestion to guess lower or higher. Why is this?:-)~MIKE~(-:On Mon, Apr 13, 2015 at 12:32 PM, Michael Havens <bmike1@gmail.com> wrote:that makes sense... thanks!:-)~MIKE~(-:On Mon, Apr 13, 2015 at 12:31 PM, Sesso <sesso@djsesso.com> wrote:The while needs to before input so that it will wait for input if the variable is not equal to 5.JasonOn Apr 13, 2015, at 12:21 PM, Michael Havens <bmike1@gmail.com> wrote:nope. that didn't fix it.---------------------------------------------------:-)~MIKE~(-:On Mon, Apr 13, 2015 at 11:46 AM, Amit Nepal <amit@amitnepal.com> wrote:You would probably want to wait and ask for the input inside the loop as well. What you seem to be doing is you ask for input and then you execute the loop not letting the user input the new number and thus running into an infinite loop.
This might fix it, not tested though :)
print("Welcome.")
g = input("Guess the number: ")
guess = int(g)
while guess != 5
print("Guess again.")
guess = int(g)
print("Correct")
Thanks
Amit
On 4/13/2015 11:01 AM, Michael Havens wrote:
print("Welcome.")
g = input("Guess the number: ")
guess = int(g)
while guess != 5:
print("Guess again.")
print("Correct")
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
PLUG-discuss mailing list - PLUG-discuss@lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss