In: Computer Science
Part A: CHALLENGE ACTIVITY 7.6.2: For loop. Printing a list.
Write the Python code to accomplish the following tasks:
• Input a string from the keyboard that represents three or more stock prices separated by spaces
o Example: ‘34.62 76.30 85.05’
• Convert the string into a Python list of floats
• Print each price in the list on a separate line with a dollar sign ($) as the first character on each line
• Print the output such that the decimal points are aligned vertically even if the user enters values such as ‘1.23 23.45 345.56’
Part B: Based on CHALLENGE ACTIVITY 7.7.3: Hourly temperature reporting.
Write the Python code to perform the following tasks:
• Use the same list of floats from part A
• Take as input from the user a two-character string from the keyboard to use as a separator during printing
o Example: user should enter something like ‘->’, ‘=>’, ‘<>’
• Write a loop that will print all elements of the list to the same line on the display
o Each element should be separated from other elements by the user-chosen separator characters including a space on each side. The space and separator should not be printed after the last number.
Example output (using input 1.23 23.45 345.56 and ->):
Enter three or more stock prices separated by spaces: 1.23 23.45 345.56
$ 1.23
$ 23.45
$ 345.56
Enter a two-character separator: -> 1.23 -> 23.45 -> 345.56
SOLUTION-
1)
CODE-
s = input('Enter stock prices separated by spaces: ')
prices = [float(v) for v in s.split()]
for p in prices:
print('${:7.2f}'.format(p))
OUTPUT-
2)
CODE-
string = input('Enter three or more stock prices seperateed by
spaces : ')
lst =string.split()
for i in lst:
print('$',i)
sep=input('Enter a two character sepearator: ')
for i in range(len(lst)):
print(lst[i], end=' ')
if i != len(lst) - 1:
print(sep, end=' ')
OUTPUT-
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------