jeudi 26 février 2015

random integers,removing elements

I have been trying several ways to remove some elements and can't seem to get it to work. The program needs the [] and ,. I have tried nums.remove(x).



import random
ROWS = 7
COLS = 1

def main():
nums = [0, 0, 0, 0, 0, 0, 0]
for r in range(ROWS):
nums[r] = random.randint(20, 80)
nums = [int(r) for r in nums]
print(nums)
print('The largest integer is',max(nums))
print('The lowest integer is',min(nums))
nums.sort()
print('The middle 5 sorted low to high',nums, )


main()


desired output:



79 30 39 33 41 43 53
The highest number is 79
The lowest number is 30
The middle 5 sorted high to low:
43 41 39 33 30


Current output:



[22, 35, 39, 24, 75, 24, 33]
The largest integer is 75
The lowest integer is 22
The middle 5 sorted low to high [22, 24, 24, 33, 35, 39, 75]




Aucun commentaire:

Enregistrer un commentaire