• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Python] Logic Help with If

Status
Not open for further replies.
Level 20
Joined
Apr 14, 2012
Messages
2,901
Code:
NumberList = []
Set_Number = [COLOR=#8888c6]input[/COLOR]([COLOR=#008080]"Enter how many numbers you want to work with." [/COLOR]+ [COLOR=#008080]"[/COLOR][COLOR=#cc7832]\n[/COLOR][COLOR=#008080]"[/COLOR])
NumberMax = [COLOR=#8888c6]int[/COLOR](Set_Number)

[COLOR=#cc7832][B]for [/B][/COLOR]x [COLOR=#cc7832][B]in [/B][/COLOR][COLOR=#8888c6]range[/COLOR]([COLOR=#6897bb]0[/COLOR][COLOR=#cc7832], [/COLOR]NumberMax):
    [COLOR=#cc7832][B]if [/B][/COLOR](x + [COLOR=#6897bb]1[/COLOR]) <= (NumberMax):
        NumberString = [COLOR=#8888c6]input[/COLOR]([COLOR=#008080]"Enter a number:" [/COLOR]+ [COLOR=#008080]"[/COLOR][COLOR=#cc7832]\n[/COLOR][COLOR=#008080]"[/COLOR])
        NumberIndex = [COLOR=#8888c6]int[/COLOR](NumberString)
        NumberList.append(NumberIndex)
        x += [COLOR=#6897bb]1
        [COLOR=#8888c6][/COLOR][/COLOR][COLOR=#8888c6]print[/COLOR](x)
    [COLOR=#cc7832][B]elif [/B][/COLOR]x > NumberMax:
        [COLOR=#8888c6]print[/COLOR]([COLOR=#008080]'reached'[/COLOR]) [COLOR=#808080]# <--- This is never reached.[/COLOR]
I actually don't know how to reach the final statement, after NumberMax iterations is reached. I tried doing:
Code:
if x <= (NumberMax - 1)
But that didn't work either.

Can anyone help? Thanks in advance.
 
Level 19
Joined
Jul 14, 2011
Messages
875
You told x to start at 0 and end when it becomes NumberMax. There is no need checking that, just print reached after the loop.

You are also incrementing x an extra time.

Python:
NumberList = []
Set_Number = input('Enter how many numbers you want to work with.\n')
NumberMax = int(Set_Number)

for x in range(0, NumberMax):
    NumberString = input('Enter a number:\n')
    NumberIndex = int(NumberString)
    NumberList.append(NumberIndex)

print('reached')
 
Status
Not open for further replies.
Top