Create a new file list-and-while.py
to save to your cs100/ch5
folder.
Here is list a=["1", "2", "3", "4", "5"]
. Use list comprehension to create list b
consisting of the integers [1, 2, 3, 4, 5]
. Print the list to test.
Use list comprehension to create the list c
consisting of all odd numbers within the range [0,20]. Print the list to test.
Use list comprehension to create the list d
consisting of all numbers divisible by 3 within the range [0, 100]. Print the list to test.
Enter next number (negative number to stop): 5
Enter next number (negative number to stop): 10
Enter next number (negative number to stop): 3
Enter next number (negative number to stop): -1
Sum of all positive numbers: 18
Enter next number (negative number to stop): 10
Enter next number (negative number to stop): 11
Enter next number (negative number to stop): 9
Enter next number (negative number to stop): 30
Enter next number (negative number to stop): 18
Enter next number (negative number to stop): -3
Sum of all positive numbers: 78
Average of all positive numbers: 15.6
Submit your working python file to Moodle.