简体   繁体   中英

why loop outputs everytime "kur"

i = int(input())
for i in range(5):
   if i <= 5:
      print("kur")
   else:
     print("zadnik")

Why everytime this outputs "kur"

You've overridden the value of i from your for condition, so your loop is seeing i as the count for the range. What you want is:

    i = int(input())
    for x in range(i+1):
        if...

This looks at the count using the input value as your limit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM