Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
If / loops help
#4
As you are trying to read the integer values stored on your "numbers_list" by a string value of "1" , so the if loop will fail always.

You can try , with 2 ways :

#One way
numbers = list(range(1,11))
#range(1,10) or range(1,11) based on your requirement
print(numbers)

for num in numbers:
    if(num==1):
        print(num)
    elif(num==2):
        print(num)
    else:
        if(num==3):
            print(num)
        else:
            continue


#Second way 
for num in numbers:
    if(num<=3):
        print(num)
    else:
        continue
buran write Dec-03-2020, 09:00 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
If / loops help - by kam_uk - Nov-29-2020, 05:49 PM
RE: If / loops help - by deanhystad - Nov-29-2020, 06:54 PM
RE: If / loops help - by jefsummers - Nov-29-2020, 10:57 PM
RE: If / loops help - by GirishaSJ - Dec-03-2020, 08:11 AM
RE: If / loops help - by buran - Dec-03-2020, 11:24 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020