Python Forum

Full Version: Unable to understand how given code takes a fixed input value, without inputting.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I got code via link in a post at stackoverflow, but unable to understand how in the code there is a fixed value taken as input, while the code asks none.

Code is at: https://ideone.com/nj4CF as given in the answer at the link on (https://stackoverflow.com/a/10907207/3693431
).

Here, fixed value of 6 is taken up.
I tried to look and found that ideone takes prog (program name: prog.py) as single parameter each time. But that means there should be 4 characters not 6. So, is the parameter stored as 'prog' and not prog.
There is nothing strange here. Suppose that you write in C
int n;
scanf("%d", &n);
this code doesn't ask anything but it reads an integer in standard input. So does the C++ code
int n;
cin >> n;
or the Python 3 code
n = int(input())
Gribouillis: sorry that just changed text while you answered.
(Jan-28-2021, 03:22 PM)jahuja73 Wrote: [ -> ]Gribouillis: sorry that just changed text while you answered. To provide link to the Cpp code, it is at :

https://ideone.com/OR4VZ.

I concur with your answer for the cpp code. Please answer the changed post for python code.
(Jan-28-2021, 11:35 AM)jahuja73 Wrote: [ -> ]Here, fixed value of 6 is taken up.
I tried to look and found that ideone takes prog (program name: prog.py) as single parameter each time. But that means there should be 4 characters not 6. So, is the parameter stored as 'prog' and not prog.
The code is meant to be run from command line and not as a script.
Then 6 is given as argument from command line.
C:\Python27
λ python prog.py 6
Output:
6 5 1 4 2 4 1 1 3 3 3 2 1 3 1 2 .....
As of 2020 is Python 2.7 officially dead💀