![](/img/trans.png)
[英]Why do I encounter the problem while trying to mask the color region using matplotlib and numpy?
[英]Why do I encounter this problem in python while loop?
我的代碼有問題,我認為這是因為我的 while 循環。 有人可以幫我嗎? 抱歉,如果評論難以理解(我先用母語添加評論)。
編輯 1:我忘記將稅收變量更改為 kambiyo_yuzde,所以它應該是這樣的:
問題是,while 循環不會以我想要的值結束。 例如,當我輸入“usd_bolu_tl”“7.500”和“sahip_tl”“2000”時,satis_tl 的值應該是 266,6 7.000,即 1866.2,而 deger_tl 的值應該是 2004。我想用我的 while 循環計算什么是它應該在每次循環時向“yeni_usd”變量添加 0.001 值,並在 satis_tl 的值(即 266.6 7.000+0.001)大於 deger_tl(即 2004)時結束
kambiyo_yuzde = 2 / 1000
usd_bolu_tl = input("current rate: ")
sahip_tl = input("how much money you have in turkish liras: ")
# money plus taxes
deger_tl = float(sahip_tl) + (float(sahip_tl) * float(kambiyo_yuzde))
print("Bu tl değerinde dolar alabilmek için kambiyo vergisi ile beraber ", deger_tl, "tl ödemeniz gerekir.")
# usd we bought with turkish liras
alinacak_usd = float(sahip_tl) / float(usd_bolu_tl)
# new currency
yeni_usd = 7.000
# selling
satis_tl = float(alinacak_usd) * float(yeni_usd)
while satis_tl < deger_tl:
print("yeni dolarin degeri: ", yeni_usd)
yeni_usd += 0.001
# to profit
print("minimum kar icin dolarinizi satmaniz gereken deger: ", yeni_usd, "'dir.")
input("cikis yapmak icin herhangi bir tusa basiniz.")
while 循環內的break語句將在第一次迭代后終止循環的執行,因此您需要重新考慮完全刪除該break
或重新考慮初始條件以停止 while 循環。
此外,根據您共享的代碼部分,我沒有看到您已初始化kambiyo_yuzde
變量的任何值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.