2015-05-21 28 views
-1
def displayChar(d): 
    if d.isalpha(): 
     print(d, "is a str") 
    elif a.isdigit(): 
     if 'float' in str(type(eval(d))): 
      print(d, "is a float") 
     else: 
      print(d, "is a int") 
    else: 
     print("Your input is not allowed") 
    del d 

a = input('Enter the first word : ') 
b = input('Enter the second word : ') 
displayChar(a) 
displayChar(b) 

之間輸出的問題沒有得到想要的輸出話說Python編程 - 每個函數調用

A is a str 
1 is a int 

,而不是「1是INT」的輸出 能收到一些解釋我好嗎?

C:\Python34\python.exe C:/Users/Suresh/PycharmProjects/Examples/func1.py 
Enter the first word : A 
Enter the second word : 1 
A is a str 
Your input is not allowed 

Process finished with exit code 0 
+1

這是執行或調試這是題外話上Programmers.SE的問題。本網站重點介紹[幫助/在線主題]中介紹的概念設計和體系結構問題。 –

+0

'elif a.isdigit():'應該是'elif d.isdigit():' –

回答

0

在你逝去的是你的名字a變量的函數,但在你的代碼測試的人反對d測試。

更改此:

elif a.isdigit(): 

這樣:

elif d.isdigit():