Python代码:请解释一下
我认为命令的前半部分是将第一个数字和第二个数字相加以得到和,后半部分是返回开始或归零的命令。我不懂python语言。您可能应该先尝试运行代码,并使用它来理解它。代码很简单;前半部分获取两个用户输入,并将它们相互添加,然后显示结果Python代码:请解释一下,python,Python,我认为命令的前半部分是将第一个数字和第二个数字相加以得到和,后半部分是返回开始或归零的命令。我不懂python语言。您可能应该先尝试运行代码,并使用它来理解它。代码很简单;前半部分获取两个用户输入,并将它们相互添加,然后显示结果 first_num = raw input ("Please input first number. ") sec_num = raw input (" Please input second number:") answer = into( first_num) +i
first_num = raw input ("Please input first number. ")
sec_num = raw input (" Please input second number:")
answer = into( first_num) +into( sec_num)
print " Now I will add your two numbers : ", answer
print " Pretty cool. huh ?
print " Now I'll count backwards from ",answer
counter = answer
while (counter >=0):
print counter
counter = counter-1
print " All done !"
至于后半部分,它取一个数字,从该数字向下计数直到零
first_num = input("Please input first number:") # get first number input
sec_num = input("Please input second number:") # get second number input
answer = int(first_num) +int(sec_num) # add up int values of the numbers
print(" Now I will add your two numbers : ", answer) # display answer
我更改了你的代码,因为你的代码行有点凌乱,有些不正确。我的这个版本适用于python3和而不是python2.7。如果你想学习python,我建议你从开始,至少把格式正确的代码放进去,还有什么问题吗?谢谢你。我确实在发帖时遇到了一些问题。顺序出了问题。再次感谢
print("Now I'll count backwards from ", answer)
counter = answer # set counter start value
while(counter >=0):
print(counter) # display counter value on each iteration
counter = counter-1 # decrement counter value on each iteration
print(" All done !)