CSE 1010 Lecture Notes - Lecture 8: 5,6,7,8

39 views2 pages
Verified Note

Document Summary

Cse 1010 - introduction to computing for engineers. Example generating a list of 10 random numbers with each number being within the range 0 to 20: Let"s try this first with a while loop: import random nums = [] n = 0 while n<10: num = random. randint(0, 20) nums. append(num) n=n+1 print(nums) Nums = [] says that the list starts out empy. N = 0 is the loop control variable. Num = random. randint(0, 20) says to generate a random number between 0 and 20 and stores it in the num variable. Nums. append(num) says to put this number at the end of the. Nums list (which is empty at the start of this loop) Note: remember, that the values in the output can range anywhere from 0 to 20! 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