Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how to put the dollar signe inside the list and the comma so the out put would l

ID: 3899967 • Letter: H

Question

how to put the dollar signe inside the list and the comma so the out put would look like this:

{$12.95, $1,234.56, $100.00, $20.50}

the code is:

# main function
def main():
list_s = []
sales =float(input('Enter the amount of monthly sales for one division (enter a negative number to finish: '))
while sales >= 0:
list_s.append(sales)
sales =float(input('Enter the amount of monthly sales for one division (enter a negative number to finish: '))
print("The list of monthly sales is :", list_s)
largest = get_largest(list_s)
print('The highest sales value is: $', largest)
lowest = get_lowest(list_s)
print('The lowest sales value is: $', lowest)
ave = get_average(list_s)
print('The average of sales value is: $', ave)
list_new = get_threshold(list_s)
print("The new list is:", list_new )

def get_largest(num):
largest = num[0]
for idx in range(1, len(num)):
if num[idx] > largest:
largest = num[idx]
return largest
def get_lowest(num):
lowest = num[0]
for i in range(1, len(num)):
if num[i] < lowest:
lowest = num[i]
return lowest
def get_average(num):
ave = sum(num) / len(num)
return ave   
def get_threshold(list_new):
threshold = float(input('enter a number to creat the new list: '))
for arr in list_new:
if arr >= threshold:
list_new.remove(arr)   
return list_new
  


main()

Explanation / Answer

Sol: The only way you can do it is if you print individual elements of the list with the proper dollar sign preceeded by a comma, rather than the complete list in one go. So, use the print function like print("The new list is:", list_new[0], ",$", list_new[1] ) and so on for all the elements of the list. The syntax may be different from what I have written but I hope that you get the idea and you write it the correct way. Let me know if you still have a problem.