Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### create list with 3 elements
- ### but you could create empty list `num = []` and later use `num.append(value)`
- #num = [x for x in range(3)]
- num = range(3)
- ### default value to get into `while`
- answer = 'y'
- ### repeat till someone answers something different then `y`
- #while(answer == 'y'): # doesn't need ()
- while answer == 'y':
- ### ask for 3 number
- for i in range(3):
- # ask for number, convert answer from text to integer, put number on list
- num[i] = int(raw_input("Enter any value for num["+ str(i) +"] : "))
- # if you use empty list you could use `num.append( int(raw_input(...) )`
- for z in range(3):
- for x in range(3):
- #if(x <= 1): # doesn't need ()
- if x <= 1:
- #if(num[x+1] > num[x]): # doesn't need ()
- if num[x+1] > num[x]:
- ### replace numbers
- #ix = num[x]
- #num[x] = num[x+1]
- #num[x+1] = ix
- num[x], num[x+1] = num[x+1], num[x] # pythonic method
- print()
- ### display list elements
- #for u in range(3):
- # print(num[u])
- for element in num: # pythonic method
- print(element)
- ### ask question and remember answer
- answer = raw_input("Try again [y/n] : ")
- ### automaticaly return to `while` with new value in `answer`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement