Первый пост здесь!
Я знаю, что таких тем мало, я их читал, но ничего не вышло.
Невозможно выйти из цикла while True (внизу кода, где находится «break») и перейти к звуковому файлу. Я новичок в программировании, только учусь ...
Заранее спасибо.
# calculating coin price
coinprice = Decimal(binance()) * Decimal(binancecr())
shorted = round(coinprice, 4)
# creating list
highestvalue = [0.0001]
# getting current time
formattime = "%H:%M:%S"
now_utc = datetime.now(timezone('UTC'))
now_currenttime = now_utc.astimezone(timezone('Europe/Berlin'))
# getting current price
print(shorted, "$", "= Starting Price", "(", now_currenttime.strftime(formattime), ")")
while True:
# getting current time
formattime = "%H:%M:%S"
now_utc = datetime.now(timezone('UTC'))
now_currenttime = now_utc.astimezone(timezone('Europe/Berlin'))
# formatting coin price
deciplaces = Decimal(binance()) * Decimal(binancecr())
rounded = round(deciplaces, 4)
# getting highest price
for item in highestvalue:
if item < rounded:
del highestvalue[0]
highestvalue.append(rounded)
# printing highest price
print(highestvalue[0], "$", "= Highest Price ", "(", now_currenttime.strftime(formattime), ")")
# calculating desired price
percentage = Decimal(highestvalue[0]) * Decimal(0.001) / Decimal(100)
percentcalc = Decimal(highestvalue[0]) - Decimal(percentage)
percconv = Decimal(percentcalc)
percround = round(percconv, 4)
# calculating percentage change
change_percent = ((Decimal(highestvalue[0]) - Decimal(rounded)) / Decimal(rounded)) * Decimal(100.00)
convchange_percent = Decimal(change_percent)
roundchange_percent = round(convchange_percent, 4)
# printing current price, desired price and percentage changes
print(rounded, "$", "= Current Price ", "(", now_currenttime.strftime(formattime), ")")
print(percround, "$", "= Desired Price ", "(", now_currenttime.strftime(formattime), ")")
print(roundchange_percent, " %", "= Percent Change", "(", now_currenttime.strftime(formattime), ")")
print("--------------------------------------")
# checking price drop
if highestvalue[0] <= percround:
# when highestvalue[0] goes below percround while True won't break and continue to a sound file
break
# time interval in seconds
time.sleep(3)
# playing sound when coin price reaches desired price
winsound.PlaySound(fname, winsound.SND_FILENAME)
Это должен означает, что highestvalue[0] <= percroun никогда не верен. Вы уверены в данных? Они должны быть чем-то отличным от того, что вы ожидаете.
Добавьте print(repr(highestvalue[0]), repr(percround)) непосредственно перед оператором if. Вы получаете желаемые ценности? repr показывает представление данных на языке Python, чтобы вы могли заметить разницу между строками и целыми числами.
Да, часть моего мозга, занимающаяся логикой (если таковая имеется), вышла из строя. Заявление о печати никогда не бывает правдой
@VitaPepe Бывает. Мы все это делаем. Вот почему так важна отладка. Вы не всегда будете правы на все 100%, поэтому вам нужно научиться находить свои ошибки, чтобы вы могли их исправить. Просто распечатать данные - самый простой способ.






Вы проверяли правильность своего утверждения с помощью
print?