OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Exit while loop by user hitting ENTER key

  • Thread starter Thread starter Candace
  • Start date Start date
C

Candace

Guest
I am a python newbie and have been asked to carry out an exercise: make a program loop until exit is requested by the user hitting <Return> only. So far I have:

Code:
User = raw_input('Enter <Carriage return> only to exit: ')
running = 1
while running == 1:
    ...  # Run my program
    if User == # Not sure what to put here
        break

I have tried: (as instructed in the exercise)

Code:
if User == <Carriage return>

and also

Code:
if User == <Return>

but this only results in invalid syntax.

How do I do this in the simplest way possible?
<p>I am a python newbie and have been asked to carry out an exercise: make a program loop until exit is requested by the user hitting <code><Return></code> only. So far I have:</p>
<pre><code>User = raw_input('Enter <Carriage return> only to exit: ')
running = 1
while running == 1:
... # Run my program
if User == # Not sure what to put here
break
</code></pre>
<p>I have tried: (as instructed in the exercise)</p>
<pre><code>if User == <Carriage return>
</code></pre>
<p>and also</p>
<pre><code>if User == <Return>
</code></pre>
<p>but this only results in invalid syntax.</p>
<p>How do I do this in the simplest way possible?</p>
 
Top