Write an expression to print each price in stock_prices. Sample output with inputs: 34.62 76.30 85.05

Students were inquired to answer a question at education and to claim what is most important for them to succeed. One which response stood out from the rest was practice. People who absolutely successful do not become successful by being born. They work hard and determination their lives to succeeding. If you wish to attain your goals, keep this in mind! shown below some question and answer examples that you would probably work with to further enhance your knowledge and gain insight that will help you to sustain your school studies.

Question:

Write an expression to print each price in stock_prices. Sample output with inputs: 34.62 76.30 85.05

Answer:

The program inputs the dollar sign to each of the user inputted stick prices. The program written in python 3 goes thus ;

t = input(‘Enter values : ‘)

#takes inputs from user for stock prices

stock_prices = [eval(x) for x in t.split()]

#splits the values based on whitespace assigns to a list variable using list comprehension

for price in stock_prices :

#iterates through the prices in the list

print(“$”, price)

#place the dollar sign behind each value and display

They would certainly hopefully assist the student deal with the question by applying the questions and answer examples. Then may possibly carry out some sharing in a group discussion and also study with the classmate with regards to the topic, so another student also take up some enlightenment and still keeps up the school learning.

READ MORE  PYTHON 7.1.6: Sandwich Sandwiches (codehs)

Leave a Reply

Your email address will not be published.