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

In PYTHON 3, (please) write function ticker() that takes a string (the name of a

ID: 3922273 • Letter: I

Question

In PYTHON 3, (please) write function ticker() that takes a string (the name of a file) as input. The file

will contain company names and stock (ticker) symbols. In this file, a company name will

occupy a line and its stock symbol will be in the next line. Following this line will be a line

with another company name, and so on. Your program will read the file and store the name

and stock symbol in a dictionary. Then it will provide an interface to the user so the user

can obtain the stock symbol for a given company. Test your code on the NASDAQ 100 list

of stock given in file nasdaq.txt.

nasdaq.txt contents:

Explanation / Answer

import os
import sys

def ticker():
  
try:
filename = raw_input("Please enter a filename: ")
txt = open(filename)

   list1 = []
   dict1 = {}

        for line in txt:
   line = line.split(' ')
   list1.append(line[0])

  

   j = 1

   for i in range(0,len(list1),2):
   dict1[list1[i]] = list1[j]
   j = j+2

  
while 1:
           try:
       comp = raw_input("Input the company name: ")
       print dict1[comp]
           except:
               print "Company name not found!!!"
               break
   return

except:
print "File not found!!!"

ticker()
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote