[Tutor] What's going on?
Alan Gauld
alan.gauld at yahoo.co.uk
Sun Apr 30 19:37:58 EDT 2023
On 30/04/2023 22:31, Ed Connell wrote:
> ###############################
> import random
> import time
>
> # build result, number choices, and choice count lists
> res = []
> nums = []
> ct = []
>
> for i in range(10):
> ct.append(0)
> nums.append(i)
I'd probably write that as
ct = [0] * 10
nums = list(range(10))
But your way works too...
>
> print('\n\n', run, ' start\n')
>
> #time.sleep(0.016) # seems to work for 0.016 or more uncommented
>
> for _ in range( 30 ): # tried 10 - 40
> random.shuffle(nums)
> res.append(nums[0])
> print(res)
> ct[nums[0]] += 1
> if ct[nums[0]] == 4:
> print( 'Removing', nums[0],nums )
> nums = nums[1:]
> print('leaving', nums )
>
> print()
> print('numbers left',sorted(nums))
> print('result',res)
> print('number used of each',ct)
> ####################################
> The problem seems to be a difference between printing and calculation speed
> but maybe not.
I don't think so, you don't have any parallel operations
going on so it just waits for each print or calculation
to happen before moving on.
> The bad output has incomplete lines as well as missing sections.
It would help if you actually showed us some bad output. Your
description is a little vague!
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list