Answer to Question #240642 in Python for Licinda Wait

Question #240642
#During the first loop of this method, previousPrice will still be 0 here,
#because it was set to currentPrice above, which also was 0 before we updated
#it above via getBitMexPrice().
#So, when we reach this point during the first loop, previousPrice will be 0
#while currentPrice would have just been updated via getBitMexPrice().
#We don't want to create the impression that the price shot up from 0 to
#currentPrice.
#ThereFore, if previousPrice == 0.0, it must be set equal to currentPrice here.
1
Expert's answer
2021-09-22T23:43:25-0400
#initialize cureent-price to zero
current_price = 0.0
print("First loop current_price is "+str(current_price))
#set previous price to current_price
previous_price = current_price
print('First loop previous_price is  '+str(previous_price))
#A method to update the current price through a user input
def getBitMexPrice():
    current_price = int(input("Enter current price: "))
    return  current_price
#Now we update the current price by calling the above method
current_price=getBitMexPrice()
#if previous price is equal to zero, set it to current_price
if previous_price == 0.0:
    previous_price = current_price
#print the current_price
print("Current price set to "+str(current_price))
#print the previous price
print("Previous price updated to "+str(previous_price))

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