Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2018
    Thanked 0 Times in 0 Posts

    Smile Student needs help

    I'm new to this site. I'm student at UCSD taking a beginning Python class. I have to write a code that reads repeatedly numbers input by the user and stops when user types , Stop, Done or Quit. Professor does not want student to use While True function in the loop. I can't get the loop to work. I'm using Python 3.5. I need help with this and any recommendation of a good interactive web site where I can practice, practice and practice !!!!

    Thank you and please hlep

    email: [email protected]

  2. #2
    Regular Coder
    Join Date
    Oct 2015
    Thanked 54 Times in 51 Posts
    What code have you got so far?

    I can't get the loop to work.
    any recommendation of a good interactive web site where I can practice
    What have you been using to find out it doesn't work?

    And what's wrong with using that?

    And it is just while that is dis-allowed?

  3. #3
    Senior Coder deathshadow's Avatar
    Join Date
    Feb 2016
    Keene, NH
    Thanked 480 Times in 468 Posts
    If he literally means no "while true" I would do while "condition" where the condition is your exit. This is a case where Pythons lack of a proper do/while is utterly banjaxed and results in more complicated (and slower) code than need be. But to be fair, I don't get why anyone would use Python by choice, it teaches and invites bad practices, and certainly isn't an easy language to use despite the wild claims.

    Something like:
    while (
        userInput != 'quit' and
        userInput != 'done' and
        userInput != 'stop'

    You would initialize the variable to something other than those three values before the while, and assign userInput inside the loop to, well, your user input. (which I'd suggest turning into lower case so the comparisons are case insensitive).

    Note, I may have goofed on the indentation, the use of whitespace as block delimiting is one of the things in python that pisses me off.
    “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.” – C.A.R. Hoare, The 1980 ACM Turing Award Lecture


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts