ecs10-11-07

ecs10-11-07 - HW5: Tally Election Results Due: Nov 14th ,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
ECS 10: Basic Concepts of Computing Prof. Bertram Ludaescher Dept. of Computer Science HW5: Tally Election Results Due: Nov 14th , 10pm What Prof. Amenta thinks you know ± functions ± lists and strings are sequences ± we can index them, concatenate them ± for loops ± Using an index variable: for i in range(10) ± Over a sequence: for point in pointList ± while loops ± decision structures: if-elif-else ± Boolean expressions ± and, or, not Variables in Functions ± Somewhat complicated rules. ± Variables defined in the main program ARE visible in the function. These are called global variables . Usually, they cannot be changed by functions. ± Variables defined in the function (including function Variables defined in the function (including function arguments) are NOT visible in the main program. These are called local variables . ± The idea is that the function should be a “black box” to the main program. Function from Last Time def is_all_digits(s): valid = True for char in s: if not (char in "0123456789"): reply is defined valid = False return valid reply = raw_input("Enter an integer: ") if is_all_digits(reply): print "That's an integer" s is not defined valid is not defined Calling a New Version ² Boolean AllowingNegative. If True, then negative numbers should be accepted. If False, then only accept positive numbers.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

ecs10-11-07 - HW5: Tally Election Results Due: Nov 14th ,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online