Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

petew71

  • 3 years ago

Ex 1.8 (pt.4) I can't figure out how to stay IN a while loop on an incorrect input by the user. I kept having the loop stop, or go on for ever. In the end i just used a recursive function! (but we've not covered functions yet..so thats a bit like cheating!)

  • This Question is Closed
  1. andrew.m.higgs
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    Hi there, What i did was to set a variable equal to 1 and then took user input into that var. Then my while loop was simply: while var % 2 != 0: var = input ("please type an even number : ") Hope this helps.

  2. petew71
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    @andrew.m.higgs Thanks Andrew. Worked just fine! I couldn't quite get my head around looping back upon a False input. I kept thinking "surely it needs another condition to test against?" But your reply showed me how simple it was! :0)

  3. andrew.m.higgs
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    Pleasure. :-)

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy