Question: Write a Python program to do the following: (a) [2 points] Generate 6 random integers from 10 to 20, inclusive. Store the random integers in
Write a Python program to do the following:
(a) [2 points] Generate 6 random integers from 10 to 20, inclusive. Store the random integers in a list. Name it list1. Display list1.
(b) [2 points] Generate 6 random integers from 15 to 25, inclusive. Store the random integers in a list. Name it list2. Display list2.
(c) [2 points] Concatenate the first 3 elements of list1 and the last 3 elements of list2 to form a new list. Name it list3. Display list3.
(d) [2 points] Concatenate the last 3 elements of list1 and the first 3 elements of list2 to form a new list. Name it list4. Display list4.
(e) [2 points] Sort elements of list3 in ascending order (i.e. from small to large). Display the sorted list3.
(f) [2 points] Sort elements of list4 in descending order (i.e. from large to small). Display the sorted list4.
(g) [2 points] Create a list to store list3 and list4. Name it big_list. This is a list of lists. The first element of big_list is list3. The second element of big_list is list4. Display big_list.
(h) [2 points] Use a set of nested loops to display every number in big_list in a separate line. Since there are 12 numbers in big_list, 12 lines of output should be generated.
(i) [2 points] Use list comprehension to select all the odd integers from list3. Store the result in a list. Display this list of odd integers.
(j) [2 points] Use list comprehension to select all the even integers from list4. Store the result in a list. Display this list of even integers.
The following is an example:
List 1: [12, 18, 20, 10, 11, 12] List 2: [20, 24, 18, 16, 25, 15] List 3: [12, 18, 20, 16, 25, 15] List 4: [10, 11, 12, 20, 24, 18] List 3 sorted in ascending order: [12, 15, 16, 18, 20, 25] List 4 sorted in descending order: [24, 20, 18, 12, 11, 10] Big List: [[12, 15, 16, 18, 20, 25], [24, 20, 18, 12, 11, 10]] Numbers in big list: 12 15 16 18 20 25 24 20 18 12 11 10 Odd numbers in List 3: [15, 25] Even numbers in List 4: [24, 20, 18, 12, 10]
QUESTION 2
A car rental company has three types of cars for customers to choose.
Compact: $30 per day for first 3 days. $26 per day for any additional days.
Mid size: $37 per day for first 3 days. $32 per day for any additional days.
Full size: $45 per day for first 3 days. $38 per day for any additional days.
Write a Python program to do the following.
(a) [4 points] Ask user to choose car type. Enter C for compact, M for mid size or F for full size. User may enter uppercase or lowercase letter. Both C and c should be accepted for compact. Both M and m should be accepted for mid size. Both F and f should be accepted for full size. If an invalid car type is entered, display "Invalid car type. Program ended." and end the program. Otherwise, proceed to part (b).
(b) [4 points] Ask user to enter number of days. Since user is expected to enter a whole number, it is safe to convert it to an integer. If 0 or a negative number is entered, display "Invalid number of days. Program ended" and end the program. Otherwise, proceed to part (c).
(c) [12 points] Calculate and display rental fee.
The following is an example:
Enter C for compact, M for mid size, F for full size: X Invalid car type. Program ended.
The following is another example:
Enter C for compact, M for mid size, F for full size: m How many days? 0 Invalid number of days. Program ended.
The following is another example:
Enter C for compact, M for mid size, F for full size: C How many days? 5 Rental fee: 142
I need help with both thank you
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
