The "loop and a half"

Bill BILL_NOSPAM at whoknows.net
Tue Oct 3 15:11:42 EDT 2017


Stefan Ram wrote:
>    Is this the best way to write a "loop and a half" in Python?

Is your goal brevity or clarity, or something else (for instance, what 
does the code written by the other members of your "team" look 
like--woudn't it be nice if it matched)?

Bill

>
> x = 1
> while x:
>      x = int( input( "Number (enter 0 to terminate)? " ))
>      if x:
>          print( f'Square = { x**2 }' )
>
>    In a C-like language, one could write:
>
> while x = int( input( "Number (enter 0 to terminate)? " ))
>      print( f'Square = { x**2 }' )
>
>    .
>




More information about the Python-list mailing list