0

I am fairly new to programming and I am having trouble figuring out this equation. I need to create a list from 100 integers that are generated at the range from 50 to 99.

From this I must create a steam and leaf plot, but I am having trouble with the random list. Must I use xrange or randomint? Any suggestions would help!

3 Answers 3

5

You need both randint and range in your list comprehension to create 100 random numbers:

data = [randint(50, 99) for i in range(100)] 
Sign up to request clarification or add additional context in comments.

3 Comments

Be sure to include from random import randint at the top.
Shouldn't it be randint(50, 99)?
@TimoSta Typo. Thanks for the heads up.
1

Here is another way that is more straightforward: (mind you, list comprehensions are more pythonic)

import random mylist = [] for i in range(100): mylist.append(random.randint(50,99)) 

Comments

1

If you can use Numpy:

import numpy as np >>> np.random.randint(low=50, high=100, size=100).tolist() [69, 93, 87, 53, 84, 54, 79, 98, 82, 86, 58, 58, 68, 62, 55, 55, 90, 98, 89, 63, 99, 64, 78, 84, 61, 58, 85, 64, 52, 79, 90, 72, 58, 53, 81, 71, 78, 90, 78, 78, 82, 61, 65, 72, 60, 61, 52, 85, 77, 62, 70, 70, 92, 80, 76, 92, 59, 55, 65, 92, 64, 53, 69, 69, 90, 99, 86, 51, 81, 67, 67, 58, 60, 85, 71, 59, 50, 60, 66, 87, 98, 75, 96, 72, 56, 85, 68, 81, 74, 72, 95, 71, 57, 59, 71, 73, 88, 79, 65, 93] 

Note that the high number is excluded, i.e. from and including low to but excluding high.

1 Comment

depends on your platform, hence "if you can use Numpy"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.