Как классифицировать число с плавающей запятой как целое число?Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Как классифицировать число с плавающей запятой как целое число?

Сообщение Anonymous »

Код: Выделить всё

`a = int(input("Geef de a waarde van de vergelijking: "))
b = int(input("Geef de b waarde van de vergelijking: "))
if a == 0 and b != 0:
print("Er is geen gehele oplossing.")
elif a == 0 and b == 0:
print("Er zijn meerdere gehele oplossingen.")
elif a != 0 and b == 0:
print("De gehele oplossing is x = 0.")
elif (b/a) != 0 and type(b/a) == int:
print("De gehele oplossing is x = " + str(b/a) + ".")
elif (b/a) != 0 and type(b/a) != int:
print("Er is geen gehele oplossing.")`
I need to make y = ax + b and i need to tell which are the points where the function is zero. My problem lies with the last two elif's. When i put a = 6 and b = -54 it calculates it as the last elif: (b/a) != 0 and type(b/a) !=int. While when you calculate -54/6 you become -9. It's as if the programe doesn't count negative numbers as integers. I'm working with dodona and I've noticed in the correction that the only that are false are the ones that classify as elif (b/Ba) != 0 and type(b/a) == int. I know that when you devide its automatically a float type. But i don't know any other option to seperate the two.
P.S. the print from the last elif says "there are no integer results". the print form the elif before that says "the integer result is x = (b/a) ."
I have tried to do it with the float type but i don't know how to classify it as an integer when it's an float.


Источник: https://stackoverflow.com/questions/781 ... an-integer
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»