Loops for文,rangeについて
・問題
Task
Read an integer . For all non-negative integers , print . See the sample for details.
Input Format
The first and only line contains the integer, .
Constraints
Output Format
Print lines, one corresponding to each .
Sample Input 0
5
Sample Output 0
0
1
4
9
16
・コメント
forを使う問題。whileでも可能。pythonのfor文は分かりにくい。
を見ればわかる通り、
という形になっている。
forとinはワンセットで登場する。
では、
変数iに0を代入→:以下を実行
変数iに1を代入→:以下を実行
・
・
変数iにn-1を代入する→:以下を実行
というループが行われている。
さらに
はn未満の数値を返す関数で、
はn以上m未満の数値を返す関数である。
例えば、
に対しては
という出力が得られ、
に対しては
という出力が得られる。
・URL
https://www.hackerrank.com/challenges/python-loops/tutorial