Getting error on bitcoin assignment

Hello :wave::wave:
Please help




I am getting the error
current_price not defined

@sanjukta16sunam

You did not call the function get_bitcoin_price(), after defining it.

Correction:

def get_bitcoin_price():
    .
    .
    .
    current_price=response["USD"]

get_bitcoin_price()

if current_price > selling_price:
    .
    .
1 Like

Thanks :+1::+1:, it worked

1 Like

Hello :wave::wave:
Again it is showing the same error
NameError : name ‘current_price’ is not defined


@sanjukta16sunam

Do the following changes, and check if it gives an appropriate response.

def get_bitcoin_price():
    .
    .
    .
    current_price=response["USD"]
    return current_price

price = get_bitcoin_price()

if price > selling_price:
    .
    .

Yes I tried it before but it was showing this error


This one worked , thanks

@sanjukta16sunam

Is it working now? Try with other names for the variable as well. Keep testing the code with small changes.

Yeah it is absolutely working now thank you
Acha can you give me some idea like how to set the buzzer to sound for 5 seconds because I think digitalWrite() does not provide such parameter or can we use tone() for buzzer

@sanjukta16sunam

Yes, you’re right. digitalWrite does not have that parameter.

To make it sound for 5 seconds, you can use a delay in the python code, to send a digital LOW signal after 5 seconds. So, the buzzer will altogether buzz for 5 seconds.

For delay, you can use time.sleep(5) in between the 2 digital HIGH and LOW functions.

Let me know if you have any other queries.

@akshayan.sinha Will you please write the code like how to delay , please

@sanjukta16sunam

As I mentioned, you can simply write,

print("Selling price increased...")
mybolt.digitalWrite("0", "HIGH")
time.sleep(5)
mybolt.digitalWrite("0", "LOW")

@akshayan.sinha
Now I am getting this error
Key error for USD
please help :pray::pray:


@sanjukta16sunam

  1. DIrectly write current_price = response, then print(price) to print the response of the bitcoin URL get. If there is no JSON key as “USD”, then that’s what the error is being returned as. Check the URL for errors in that case.

  2. Your mybolt.digitalWrite(‘o’, LOW) has ‘o’ in it. It is supposed to be any of the GPIO pins from 0 - 4. In your case, ‘0’ and not ‘o’.

I stumbled upon this thread from two years ago, and it seems like you were facing an error with your Bitcoin assignment. No worries, I’m here to lend a hand! If you were getting the ““current_price not defined”” error, it means that the variable ““current_price”” is not properly defined in your code. To fix this, make sure you’ve declared and assigned a value to the ““current_price”” variable before using it.