-3
def Answer():
     A = var1.get()
     if "." not in A and A.isdigit():
         Right1.insert(END,str(A)+"est un entier")

     elif "." in A  and A.isdigit():

          B,C = A.split(".")
          Right1.insert(END,str(B)+"est decimal" + str(C)+"est entier")
    else :
         Right1.insert(END,"ERROR")

That is my function Answer for my thinker. When I enter an Interger(12), I see the "Integer(12) est un entier". But when I enter a decimal number (12.7), it prints: ERROR instead of splitting the number to two part. I should have on my screen: "12 est decimal" "7 est entier". Any ideas where I am doing wrong?

Dadep
  • 2,796
  • 5
  • 27
  • 40
edmundo
  • 11
  • 4

1 Answers1

2

You should check to see what type the values are before taking an action. 12 is an int and 12.7 is a float.

So using that information we can do the below:

a = [12, 12.7]

for i in a:
    if type(i) == int:
        print(str(i)+" est un entier.")
    elif type(i) == float:
        print(str(i).split(".")[0]+" est decimal "+str(i).split(".")[1]+" est entier.")
Ethan Field
  • 4,646
  • 3
  • 22
  • 43