Answer to Question #248570 in Python for Yami

Question #248570
#loop through displayList
for i in range(0,len(displayList)):
    #Test if the fist item in the current sub-list contains the text "Price Level
    #Tip: Remeber that each sub-list is a (displayList). So you have
    #       to access its items via displayList followed by TWO indexes.
    if i[0] == 'priceLevel':
        #Extract the second item from the current sub-list into variable called priceLevel
        priceLevel = i[1]
    #Test if priceLevel is between pPrice and cPrice OR
    #priceLevel == pPrice OR
    #        priceLevel == cPrice
    if priceLevel >= self.__previousPrice and priceLevel <= self.__currentPrice or priceLevel == self.__previousPrice or priceLevel == self.__currentPrice:
        #Sound the alarm. Pass in the frequency and duration.
        if self.__currentPrice > self.__previousPrice:
            frequency = 800
            duration = 700
        else:
            frequency = 400
            duration = 700
        winsound.Beep(frequency, duration)
        #Print the text 'Alarm' with a green background color, so that the user
        #can go back and check when the alarm was sounded.
        print(Back.GREEN + "Alarm" + Style.RESET_ALL)







1
Expert's answer
2021-10-08T04:34:58-0400
import winsound


class Play(object):

    def __init__(self):
        self.__currentPrice = None
        self.__previousPrice = None

    def ls(self, previousPrice=None, currentPrice=None):
        global priceLevel
        displayList = ['Price level']
        # loop through displayList
        for i in displayList:
            print(i[0])
            for i in range(0, len(displayList)):
                if i[0] == "Price Level":
                    priceLevel = i[1]
                if previousPrice <= priceLevel <= currentPrice or priceLevel == previousPrice or priceLevel == currentPrice:
                    # Sound the alarm. Pass in the frequency and duration.
                    if self.__currentPrice > self.__previousPrice:
                        frequency = 800
                        duration = 700
                    else:
                        frequency = 400
                        duration = 700
                    winsound.Beep(frequency, duration)

                    # Print the text 'Alarm' with a green background color, so that the user
                    # can go back and check when the alarm was sounded.
                    print("Alarm")


if __name__ == '__main__':
    displayList = ['Price level']
    play = Play()
    # function call
    play.ls(0, 100)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS