I'm really not clear here on what it is you want. Could you tell us what the input and output is for your function for a relevant input value? We can also probably convert a while loop that does what you want to the correct for loop. Python has a lot of facilities to be able to use for loops instead of while loops.

Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.

Thank you for the reply. The code above was meant to use the for statement to loop the heights of the students and store them into and check after the input that it is a digit that was input and if it isn't then it decreases the delared value shown as (y = y - 1) thus it would show the same student number again. If that makes sense I'm not sure if I explained it properly

for i in range(x): while True: input_height = input('Please enter the height of Student %s \n' % i) if input_height.isdigit(): heights.append(input_height) break else: print('That is not a valid height')

Just a few extra notes:

Appending to a global list like that is rarely a good idea. Better to create a list inside the function and return it.