def g():
a = input("tam sayı yaz")
if type(a) == float or type(a) == str:
print("tam sayı değil",type(a))
g()
else:
print("bu tam sayı",type(a))
g()
g()
Kodum girdiğim tüm inputları string olarak görüyor. Integer girdiğimde bile. Neden acaba?
def g():
a = int(input("tam sayı yaz"))
if type(a) == float or type(a) == str:
print("tam sayı değil",type(a))
g()
else:
print("bu tam sayı",type(a))
g()
g()
def g():
a = int(input("tam sayı yaz"))
if type(a) == float or type(a) == str:
print("tam sayı değil",type(a))
g()
else:
print("bu tam sayı",type(a))
g()
g()
def g():
a = int(input("tam sayı yaz"))
if type(a) == float or type(a) == str:
print("tam sayı değil",type(a))
g()
else:
print("bu tam sayı",type(a))
g()
g()
Hocam basitçe try bloğu içerisindeki işlemler gerçekleşmezse veya durumlar mevcut olmazsa bizim istediğimiz hatayı ekrana yazdırır. Bir diğer kullanımı Exception olabilir, bunda Python, hata ne ise o hatayı ekrana yazdırır.
Python:
def g():
a = input("tam sayı yaz")
try:
a = int(a)
print("bu tam sayı",type(a))
g()
except Exception as hata:
print(hata)
g()
g()