0

Urgent help needed for python code

Hi, I’ve recently started python and I need help with this question concerning lists and arrays for schoolwork I need to hand in soon. How do I create a list (eg. [0,1,2,3,4,5,6,7,8,9])starting with an empty list and using loop and append commands. Also how do I creat an array [0,1,2,3,4...500] and then loop through hsing a for loop to sum all the numbers. Finally how do I create an array of 20 random integers between 1-100 inclusive. All help is appreciated and I thank all of you in advance!

2nd Nov 2017, 9:34 PM
Simon Luo
Simon Luo - avatar
2 Answers
+ 1
Thankyou so much! Sorry, I should have tried myself first but I was just running low on time. Next time I will definitely try before asking for help!
3rd Nov 2017, 8:15 AM
Simon Luo
Simon Luo - avatar
0
1. Try at least, before asking for help with schoolwork. 2. Here: i) arr = [] for number in range(10): arr.append(number) ii) arr = [] sum = 0 for number in range(501): arr.append(number) for value in arr: # it'd be quicker to use sum(), but you wanted a for loop sum += value iii) import random arr = [] for _ in range(20): arr.append(random.randint(1, 100))
2nd Nov 2017, 10:14 PM
LunarCoffee
LunarCoffee - avatar