For next loops

Neil Cerutti neilc at norwich.edu
Mon Jul 23 09:30:26 EDT 2018


On 2018-07-23, no at none.invalid <no at none.invalid> wrote:
> never mind.
> x = range (5)
> y = range (5)
> for ply in x:
>
>     for com in y:
>         if ply==com:
>             result="Tie"
>
>         print(ply,com,result)
>         result = ""

Something like this is possible. "x", "y" and "result" can be
unecessary.

for ply in range(5):
    for com in range(5):
        print(ply, com, end='')
        if ply == com:
            print(" Tie")
        else:
            print()

-- 
Neil Cerutti



More information about the Python-list mailing list