2017-06-02 58 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

尼斯。我是新来的蟒蛇我学习所有网站给你。 –