import random; while True: print (random.randrange (1, 100 + 1, 2))
I'm trying to generate infinite amount of odd numbers with range from 1 - 100
import random; while True: print (random.randrange (1, 100 + 1, 2))
I'm trying to generate infinite amount of odd numbers with range from 1 - 100
Semicolons cannot be used to join arbitrary statements, only "small" statements:
stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | nonlocal_stmt | assert_stmt)
A small statement is (roughly speaking) any statement that doesn't involve indentation.
Instead, you need to separate the import and the loop with a literal newline. If your shell supports it, you can use
python -c $'import random\nwhile ...'
Otherwise, you need to relax your definition of 'one-liner':
python -c 'import random
while ...
'