0

Consider

a=2;s=0;while s<11: print(s*a);s+=1

I am getting

    a=2;s=0;while s<11: print(s*a);s+=1
                ^
SyntaxError: invalid syntax

I want everything in a single line. Is it possible?


The reasoning for monstrosities like this is to try and beat a code golf

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • 1
    Do you need a `while`? Here, this is basically just a loop over `range(11)`. Something like `a=2;print(*(s*a for s in range(11)), sep="\n")`, or `a=2;print("\n".join(str(s*a) for s in range(11)))`. – Carcigenicate May 04 '21 at 17:24
  • _"I want everything in a single line."_ Why though? Putting everything in a single line doesn't speed up your code or have any tangible benefits. – Pranav Hosangadi May 04 '21 at 17:25
  • @Carcigenicate I am doing very ugly and hacky things to try and beat a code golf. Doing what I have to do. – Gulzar May 04 '21 at 17:43
  • @12944qwerty `a=2;s=0;while s<11: print(s*a)` gives the same (compilation) error. The problem is *before* the while. – Gulzar May 04 '21 at 17:48
  • Ah, that's where the confusion came. Please put the full traceback then. – 12944qwerty May 04 '21 at 17:49
  • @12944qwerty see edit please. – Gulzar May 04 '21 at 18:02

0 Answers0