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 >>>
返回
武宁县| 宜良县| 桦川县| 大埔区| 汕尾市| 枣庄市| 淮滨县| 焉耆| 景宁| 子长县| 邹城市| 铅山县| 巢湖市| 阳曲县| 东宁县| 平顶山市| 喀喇沁旗| 淳化县| 长垣县| 子洲县| 明光市| 寿阳县| 静安区| 海口市| 马龙县| 邛崃市| 湟源县| 丁青县| 楚雄市| 武安市| 肃南| 晋州市| 化德县| 安阳市| 定陶县| 松滋市| 十堰市| 广灵县| 萨嘎县| 新乡县| 河津市|