I just started learning to code in python and here is my first program. Why doesn't quit program when I enter the letter "q".
print("bu program sıcaklığa göre suyun durumunu gösterir")
while True:
s=input("lütfen sıcaklığı giriniz.çıkmak içn q ya bas")
if s=="q":
print("çıkılıyor")
break
try:
s_int=int(s)
except ValueError:
print("Lütfen sadece sayı giriniz")
raise
if s_int<0:
print("Durum Buzdur")
elif s_int>=100:
print("Durum Buhar")
else:
print("Durum su")
s=int(input("lütfen sıcaklığı giriniz"))
It's not possible for s to be equal to an alphabetical character "q", if you are immediately converting your input to an int (an int is a number).
If anything your program should immediately jump to line print("Lütfen sadece sayı giriniz") because attempting to convert a "q" to an integer raises a ValueError.
To fix this, you could first compare the raw input to "q". If it's not equal, then the next step you try converting it to an int.
s=input("lütfen sıcaklığı giriniz")
if s=="q":
print("çıkılıyor")
break
try:
s_int = int(s)
except ValueError:
print("Please enter a valid integer or 'q'")
raise
if s_int<0:
print("Durum Buzdur")
elif s_int>=100:
print("Durum Buhar")
else:
print("Durum su")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With