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!
2 Respostas
+ 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!
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))