Python,If tests

返回

>>> if 1: ... print 'true' ... true >>> >>> if not 1: ... print 'true' ... else: ... print 'false' ... false >>> x = 'killer rabbit' >>> if x == 'roger': ... print "how's jessica?" ... elsif x == 'bugs': File "<stdin>", line 3 elsif x == 'bugs': ^ SyntaxError: invalid syntax >>> elif x == 'bugs': File "<stdin>", line 1 elif x == 'bugs': ^ SyntaxError: invalid syntax >>> if x == 'roger': ... print "how's jessica?" ... elif x == 'bugs': ... print "what's up doc?" ... else: ... print 'Run away! Run away!' ... Run away! Run away! >>> >>> choice = 'ham' >>> print {'spam': 1.25, ... 'ham': 1.99, ... 'eggs': 0.99, ... 'bacon':1.10}[choice] 1.99 >>> if choice == 'spam': ... print 1.25 ... elif choice == 'ham': ... print 1.99 ... elif choice == 'eggs': ... print 0.99 ... elif choice == 'bacon': ... print 1.10 ... else File "<stdin>", line 9 else ^ SyntaxError: invalid syntax >>> else: File "<stdin>", line 1 else: ^ SyntaxError: invalid syntax >>> if choice == 'spam': ... print 1.25 ... elif choice == 'ham': ... print 1.99 ... elif choice == 'eggs': ... print 0.99 ... elif choice == 'bacon': ... print 1.10 ... else: ... print 'Bad choice' ... 1.99 >>>
返回
弥勒县| 东山县| 青川县| 监利县| 沽源县| 孟州市| 昔阳县| 天津市| 屯门区| 道孚县| 鱼台县| 尤溪县| 科尔| 荔波县| 荆门市| 乾安县| 鹤庆县| 乌兰察布市| 汶川县| 广宗县| 宜阳县| 清新县| 望都县| 黄浦区| 南平市| 余江县| 湖北省| 灌阳县| 文安县| 平南县| 措美县| 册亨县| 鄂温| 南靖县| 泰州市| 南靖县| 平顺县| 鄂温| 孝感市| 门头沟区| 南宁市|