Control Flow, Comparators & Conditional Syntax


Initially published on 24/04/2015 Start with : Post 2
Control FlowThe ability to choose from different situations based on what's happening in the program. Example :- >>> def stadium(): print "You've entered the stadium!" print "Do you want to bat or field ?" answer = raw_input("Type bat or field and hit 'Enter'.").lower() if answer == "bat" or answer == "b": print "The pitch is a batting paradise" elif answer == "field" or answer == "f": print "It's a very big park, the bowlers have equal advantage" else: print "Let's watch the match." stadium() stadium() Comparators Equal to (==) Not equal to (!=) Less than (<) Less than or equal to (<=) Greater than (>) Greater than or equal to (>=) Boolean Operators AND
Picture
OR
Picture
NOT
Picture
Conditional Syntaxdef batsman(score): if score > 100: return hundred elif score < 50: return fifty else: return 1 print batsman(4) print batsman(5) print batsman(6) (* The above exercises are available at codeacademy)

Leave a comment


Please note, comments must be approved before they are published