我是编程新手,我选择 python 作为我的第一语言,因为它很简单。但我在这里对这段代码感到困惑:
option = 1
while option != 0:
print "/n/n/n************MENU************" #Make a menu
print "1. Add numbers"
print "2. Find perimeter and area of a rectangle"
print "0. Forget it!"
print "*" * 28
option = input("Please make a selection: ") #Prompt user for a selection
if option == 1: #If option is 1, get input and calculate
firstnumber = input("Enter 1st number: ")
secondnumber = input("Enter 2nd number: ")
add = firstnumber + secondnumber
print firstnumber, "added to", secondnumber, "equals", add #show results
elif option == 2: #If option is 2, get input and calculate
length = input("Enter length: ")
width = input("Enter width: ")
perimeter = length * 2 + width * 2
area = length * width
print "The perimeter of your rectangle is", perimeter #show results
print "The area of your rectangle is", area
else: #if the input is anything else its not valid
print "That is not a valid option!"
好的好的,我得到了Option
变量下面的所有东西。我只是想知道为什么我们分配 的值Option=1
,为什么我们将它添加到程序的顶部,以及它的功能是什么。我们也可以改变它的值。请让我用简单的语言理解它,因为我是编程新手。