CSE 1010 Lecture 6: 9/29/16 More Loops
21 views2 pages
4 Oct 2016
School
Department
Course
Professor
jadetortoise401 and 55 others unlocked
84
CSE 1010 Full Course Notes
Verified Note
84 documents
Document Summary
Generate a list of random numbers using a while loop. Generate a list of 10 numbers, each in the range 0 to 10. Nano numlist1. py import random nums = [] n = 0 while n < 10: num = random. randint(0, 10) nums. append(num) n = n + 1 print(nums) The values on n is 0 through 9, but it also includes 10, it is the exiting condition. It gets the list, and the list keeps growing. Generate a list of random numbers using a for loop. Nano numlist01. py import random nums = [] for n in range(10): num = random. randint(0, 10) nums. append(num) # you do not need to include n = n + 1 because the for loop does it itself print(nums) Calculating an average using a while loop. Given a list of random numbers, calculate the average of the numbers in that list.