Question

In: Computer Science

On Python perform the following operations on numbersList = [-11, -4, 5, 12, 13, 14, 19]...

On Python perform the following operations on numbersList = [-11, -4, 5, 12, 13, 14, 19]

a) Ask the user to enter a number to add to the list. Append the number to the list if the number does not already exist in the list. If the number already exists in the list notify the user.

b) Improve your code by using a loop. Keep asking the user for a new element to add to the list until they enter a number which is not in the list.

c) Improve your code further by adding an outer loop. Ask the user if they want to continue adding an element to the list. When the user is done with adding elements, print the number of the elements in the final list.

Solutions

Expert Solution

a)

numbersList = [-11, -4, 5, 12, 13, 14, 19]
print(numbersList)
N=int(input(" Enter a number to add to the list: ")) #integer number input by user
if N in numbersList:                 #check if the number is present in list or not
     print("Number already exist in the list")
else:
     numbersList.append(N)    #apeend number to the given list
     print(numbersList)

b)

numbersList = [-11, -4, 5, 12, 13, 14, 19]
print(numbersList)
while True: #iterating loop until the break keyword appear
     N=int(input(" Enter a number to add to the list: "))
     if N in numbersList:
         print("Number already exist in the list")
         break
     else:
         numbersList.append(N)
         print(numbersList)

c)

numbersList = [-11, -4, 5, 12, 13, 14, 19]
print(numbersList)
k="y"
while k.lower()=="y":#iterating outer loop until user entetred y
  while True:
     N=int(input(" Enter a number to add to the list: "))
     if N in numbersList:
         print("Number already exist in the list")
         break
     else:
         numbersList.append(N)
         print(numbersList)
  k=input("If you want to continue press 'y': ")
print("Number of elements in the final list = ",len(numbersList))


Related Solutions

On Python perform the following operations on numbersList = [-11, -4, 5, 12, 13, 14, 19]...
On Python perform the following operations on numbersList = [-11, -4, 5, 12, 13, 14, 19] a) Ask the user for an index number. Check to see if the index is in the range. If it is, pop the element from that index. Print the popped element as well as the list. If the index is out of range notify the user. b) Improve your code by using a loop. Keep asking the user for an index until they enter...
11 12 11 10 14 15 16 12 11 10 12 20 13 32 35 14...
11 12 11 10 14 15 16 12 11 10 12 20 13 32 35 14 41 12 10 11 12 12 13 16 14 17 18 19 12 13 14 10 10 14 11 10 12 14 12 13 16 14 17 19 20 15 25 15 45 45 44 41 40 14 18 19 24 20 26 36 34 30 31 50 15 12 Find the following: Mean? (1) Median (2), and Mode? Find : Q3, Q1, D7,...
Match No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14...
Match No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Player A 8 42 56 68 91 123 12 46 57 137 5 80 14 10 19 Player B 38 44 46 59 57 61 48 42 51 39 58 41 55 45 68 1. For the given data set representing the runs scored by two players in last 15 matches, conduct the following analysis: i. Which average you will use to summarize...
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of Aides Absent 5 8 11 15 4 2 7 1 4 6 14 19 3 5 8 In which of the following ranges you can find the Upper Control Limit of the control chart? 0.1427 0.1536 0.1677 Not computable with information available In which of the following ranges you can find the Lower Control Limit of the control chart? Does not exit...
student 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
student 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Test score 67 67 87 89 87 77 73 74 68 72 58 98 98 70 77 Above we have the final averages of the last stats and I want to know if the class average falls within the boundaries of all my statistics classes for the past 20 years. Find the sample size, mean, and standard deviation of the data above (Table 1)....
Promotional expenses(x) Sales(y 7 12 10 14 9 13 4 5 11 15 5 7 3...
Promotional expenses(x) Sales(y 7 12 10 14 9 13 4 5 11 15 5 7 3 4 a) draw the scatter plot and draw the line of best fit b) Calculate and interpret the correlation between promotional expenses and sales C) Calculate the regression equation( calculate the slope and intercept of the regression line d)Interpret the slop coefficient of regression equation e)Using the regression equation calculate the sales volume with respect to promotional expense of 4. f) Obtain the coefficient...
Perform each task, given the following set of data. 3 6 11 13 19 23 (a)...
Perform each task, given the following set of data. 3 6 11 13 19 23 (a) Viewing the data as a sample drawn from a larger population, find the sample standard deviation, s, of the data. (Round your answer to two decimal places.) s = (b) Viewing the data as an entire population, find the population standard deviation, σ, of the data. (Round your answer to two decimal places.) σ = (c) How do the answers to parts (a) and...
Use the sample space (5, 6, 7, 8, 9, 10, 11, 12, 13, 14) to find...
Use the sample space (5, 6, 7, 8, 9, 10, 11, 12, 13, 14) to find the probability for a random selected a) P(integer) b) P(less than 10 | less than 13) c) P(greater than 8 | less than 11) d) P(greater than 7 | greater 12)
For the data set 1 4 4 4 7 7 7 9 12 13 14 14...
For the data set 1 4 4 4 7 7 7 9 12 13 14 14 14 15 16 16 17 17 19 20 22 23 23 24 24 25 26 26 27 29 29 31 34 34 35 35 36 37 43 44 44 47 48 48 49 50 52 52 54 54 55 56 56 58 58 59 59 60 64 64 65 66 69 69 73 76 76 77 77 79 (a) Find the 76th percentile. (b)...
Miles Freq 0-4 3 5-9 14 10-14 13 15-19 4 Select the most appropriate sentence corresponding...
Miles Freq 0-4 3 5-9 14 10-14 13 15-19 4 Select the most appropriate sentence corresponding to two standard deviations. *About 68% of students drive between 5.5212 miles and 13.7730 miles to somewhere *At least 88.9% of students drive between -2.7306 miles and 22.0248 miles to *About 99.7% of students drive between 1.3953 miles and 17.8989 miles to *About 68% of students drive less than 22.0248 miles to *About 95% of students drive between 5.5212 miles and 13.7730 miles to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT