Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

Why do I encounter this problem in python while loop?

I have a problem with my code and I think it's because of my while loop. Can someone help me with it? Sorry if comments are complicated to understand (I added comments in my native language first).

Edit 1: I forget to change taxes variable to kambiyo_yuzde, so it should have been look like this:

The problem is, the while loop doesn't end at value i want to get. For example, when i entered "usd_bolu_tl" "7.500" and "sahip_tl" "2000", value of satis_tl should be 266,67.000 which is 1866.2, and value of deger_tl should be 2004. What i want to calculate with my while loop is that it should add 0.001 value to the "yeni_usd" variable every time it loops and end when satis_tl's value (which is 266.67.000+0.001) is bigger than deger_tl (which is 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.")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The break statement inside the while loop will terminate the execution of the loop after the first iteration, so you'd need to reconsider to remove that break at all or reconsider the initial condition to stop your while loop.

Additionally, as per the section of your code shared I don't see that you have initialized any values for the kambiyo_yuzde variable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.7k users

...