2017-06-02 30 views
-3
x=int(input(1)) 
y=int(input(2)) 

if x==y: 
    print('x and y are equal') 
else: 
    print('x and y are not equal') 

print('thanks') 
+2

看起來錯誤不是來自程序本身,它沒有任何問題。 –

+1

你真的想用'1'和'2'作爲輸入提示嗎?否則該程序似乎工作 –

回答

1

首先,您可以在任何教程,書籍或在此處搜索的問題中找到此信息。無論如何......

輸入將在控制檯中提示時顯示將顯示給用戶的文本。

>>> input("Enter a number: ") 
Enter a number: 

然後,我可以輸入我想要的數字並按回車。 (回到上一行)

Enter a number: 4 

然後,您分配輸入的值將有「4」。請注意,這是一個字符串。

因此,int(input(1))沒有做你認爲的事情。您的程序仍在「運行」,因爲它正在等待用戶輸入。

x=int(input("Enter first number: ")) 
y=int(input("Enter second number: ")) 

if x==y: 
    print('x and y are equal') 
else: 
    print('x and y are not equal') 
print('thanks') 

輸出:

Enter first number: 1 
Enter second number: 1 
x and y are equal 
thanks 
0

它繼續運行,因爲x和y是輸入。輸入要求你輸入一些東西給他們一個價值。刪除輸入(...)。另外,int()是不必要的,因爲1和2已經是整數。

x = 1 
y = 2 
if x == y: 
    print("x and y are equal") 
else: 
    print("x and y are not equal") 
print("thanks") 
0

您好Nitesh先生,當你執行你的計劃也得到輸出,但編程或標準的方式

你的程序是沒有錯的無效程序。

如果你是初學Python的人,首先閱讀深層次的基本編程和閱讀編程標準。我給下面的網站蟒蛇... 1)http://docs.ckan.org/en/latest/contributing/python.html(Python編程標準)
2)https://www.tutorialspoint.com/python/(Python的學習)
3)https://docs.python.org/3/tutorial/(Python的學習)

我給你的答案的問題是下面,

x = int(input("Enter the value of x: ")) 
y = int(input("Enter the value of Y: ")) 

print "Now check both are equal or not..." 

if x != y: 
    print('x and y are not equal.') 
elif x == y :`enter code here` 
    print('x and y are equal') 

print('Thank you.') 
+0

尼斯。我是新來的蟒蛇我學習所有網站給你。 –