Skip to content

Latest commit

 

History

History
47 lines (25 loc) · 1.13 KB

File metadata and controls

47 lines (25 loc) · 1.13 KB

Unit 4 Practice

Exercise 5 - More Number Lists

Use a loop and random.randint() to generate a list of ten random_numbers between 1 and 100.

5.1

Count the number of even numbers in the list. Hint: You can use % 2 to determine if a number is even or odd.

Output

Numbers: [64, 3, 55, 94, 40, 56, 40, 69, 54, 3]
There are 6 evens: [64, 94, 40, 56, 40, 54]

5.2

Reverse the list using a loop and without any methods or built-in functions

Output

numbers: 5, 90, 43, 52, 21, 49, 92, 40, 33, 84

[25, 8100, 1849, 2704, 441, 2401, 8464, 1600, 1089, 7056]

5.3

Sort the list of numbers in ascending order without using methods or built-in functions.

Output

numbers: [62, 23, 56, 30, 55, 60, 31, 91, 93, 45]
sorted:  [23, 30, 31, 45, 55, 56, 60, 62, 91, 93]

Hint:

One way to accomplish this is by implementing a bubble sort algorithm.

View bubble sort pseudocode here.

Exercise 5 solution