0% found this document useful (0 votes)
4 views

Assignment_18

The document outlines a programming assignment involving various list operations, including user input for integers, random number generation, and list modifications. It details specific tasks such as counting items, reversing lists, and performing calculations like averages and sorting. Additionally, it includes instructions for creating lists through loops and manipulating strings and numbers based on user input.

Uploaded by

24divya693
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment_18

The document outlines a programming assignment involving various list operations, including user input for integers, random number generation, and list modifications. It details specific tasks such as counting items, reversing lists, and performing calculations like averages and sorting. Additionally, it includes instructions for creating lists through loops and manipulating strings and numbers based on user input.

Uploaded by

24divya693
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
1219724, 620 PME ‘Assignment_18_List #1, List Operations with User Input awrite a progran that asks the user to enter a List of integers. Perform the follow #(a) Print the total number of items in the List. #(b) Print the Last item in the List. #(c) Print the List in reverse order. #(d) Print aquot;Yesaquot; if the List contains a 5 and "No" otherwise. #(e) Print the number of fives in the List. (Ff) Remove the first and Last items from the List, sort the remaining items, and p #(g) Print how many integers in the List are Less than 5. us{] rev_l1-[] for i in range(5): val (input (‘Enter nunber 11 append(n) print(f'The list is: {11}') items=len(11) print(f'The no. of itens in list is: {items}') # (a) for i in 11: if index==1en(11)-1: print(f'The last item in the list is (1)') # (b) else: indexsindex+1 for i in reversed(11): rev_11.append(i) print(fithe list in reverse order is {rev.l4}') # (c) for i in 11 af is5) print(#"{i} : Squot;Yestquot') —# (d) count=count+ else: print(f'{i} : aquot ;No"') if cb: counti-counti+1 —# (g) print(#'The count of 5 is : {count}') — # (e) 11..pop(2) 11. pop(1en(11)-1) print(11) print(f'the count of integers less than 5 is: {count1}') print(f'The sorted list after pop is {sorted(11)}") —# (f) fi:11C:/Usors/LonovorDownloadsiAssignment_18_Lishtmt wa 1219724, 620 PME ‘Assignment_18_List The list is: [8, 7, 5, 4, 3: The no. of items in list is: 5 The last item in the list is 3 The list in reverse order is [3, 4, 5, 7, 8 quot ;No" quot ;No" + " ;Yesquot + Aquot ;Nokquot 1 Aquot ;NoBquot 5 The count of $ is : 1 17, 5, 4] the count of integers less than 5 is: 2 The sorted list after pop is [4, 5, 7] In # 2. Random Number List Analysis # Write a program that generates a List of 28 random numbers between 1 and 100. Per # following tasks: # (a) Print the List. # (b) Print the average of the elements in the List. # (c) Print the Largest and smallest values in the List. # (d) Print the second Largest and second smallest entries in the List. # (e) Print how many even numbers are in the List. import random u-[] rev_lt1=[] count=@ aver? for i in range(20): n-random.randint (1,102) 11. append(n) print(f'The list 4: itens-Len(11) print(f'The no. of items in list is: {items}') for i in li: if 12: count=count+1 ave-averi print(f'Aaverage of the elements in the list is : {avg/items}') # (b) print(f*Count of even numbers in the list are: {count}') # (e) 2 (ly) # (a) The list is: [53, 57, 19, 43, 86, 82, 72, 79, 17, 28, 67, 69, 85, 1, 31, 63, 71, 18, 31, 86) The no. of items in list is: 20 Average of the elements in the list is : 52.9 Count of even numbers in the list are: € 3. Modify and Transform a Predefined List Start with the list [8, 9, 10]. Perform the following tasks: (a) Set the second entry (index 1) to 17. (b) Add 4, 5, and 6 to the end of the list. (c) Remove the first entry from the list. (d) Sort the list. (e) Double the list. (f) Insert 25 at index 3. The final list should equal [4, 5, 6, 25, 18, 17, 4, 5, 6, 10, 17]. {ie:1/C:1Usors/Lenovo/Downloads!Assignment_16_Lis him 218 1219724, 620 PME ‘Assignment_18_List 4. Replace Numbers Greater than 10 Ask the user to enter a list containing numbers between 1 and 12. Replace all entri are greater than 1¢ with 1¢. 5. Modify Strings in a List Ask the user to enter a list of strings. Create a new list that consists of those = characters renoved. 6. Create Lists Using Loops Using a for loop, create the following lists: (a) A list consisting of the integers © through 49. (b) A list containing the squares of the integers 1 through 50. (c) The list [8#39;a8#39;, 'bb8#39;, 8#39;ccc', 8#39;dddd8H39;, ...] that e 7. Element-wise Sum of Two Lists lirite a program that takes any two lists L and M of the same size and adds their el to form a new list N whose elenents are the suns of the corresponding elenents in L For instance, if L = (3, 1, 4] and M = [1, 5, 9], then N should equal [4, 6, 13]. 8. List of Factors Write a program that asks the user for an integer and creates a list that consists integer. 9. Dice Roll Probabilities ieite a program to simulate rolling two dice about 10,000 times and conpute the per rolls that result in sums of 2, 3, 4, ..., 12. 10. Rotate a List Wieite a program that rotates the elements of a list so that the element at the firs the second index, the element in the second index moves to the third index, and the last index moves to the first index 11. Patterned List of Ones and Zeroes Using a for loop, create the list [1, 1, @, 1, ®, @, 1, ®, @, @ 1, @, 2 2 @ 1, between the last two ones. 12. Longest Run of Zeroes Wieite a program that generates 100 random integers (either @ or 1). Find the longes Which is the largest number of consecutive zeroes in the list. 13. Remove Duplicates ieite a program that renoves any repeated items from a list so that each item appea once. For instance, the list [1, 1, 2, 3, 4, 3, ®, @] would becone [1, 2, 3, 4, 0]. 14. Unit Conversion lirite a program that asks the user to enter a length in feet. Provide the user with from feet to: 1, Inches 2. Yards 3. Miles 4, Millimeters 5. Centimeters, {ie:1/C:1Usors/Lenovo/Downloads!Assignment_16_Lis him aia 1219724, 620 PME 6. Meters 7. Kiloneters Use lists to simplify the conversion. {ie:1/C:1Usors/Lenovo/Downloads!Assignment_16_Lis him ‘Assignment_18_List 48

You might also like