CSE 1010 Lecture 6: 9/29/16 More Loops

21 views2 pages
jadetortoise401 and 55 others unlocked
CSE 1010 Full Course Notes
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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions