


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



While loops - ANSWER - executes a series of steps while some condition is true
return c# or without the interim assignment to c def add_two(a, b): return a + b Sets - ANSWER collections of unique >> new_set = { 1, 2, 3, 4, 4, 4,'A', 'B', 'B', 'C'} but unordered items. Ex: >> new_set = { 1, 2, 3, 4, 4, 4,'A', 'B', 'B', 'C'} List - ANSWER A Python data type that holds an ordered collection of values, which can be of any kind. This is equivalent to an "array" in many other languages. Python lists are "mutable," implying that they can be changed once created. String - ANSWER Strings store characters and have many built-in convenience methods that let you modify their content. The len() Function: - ANSWER returns the number of items contained in a list. Example: >> mylist = [0,4,5,2,3,4,5] >> len(mylist) Single Line Comments: - ANSWER Augmenting code with human readable descriptions can help document design decisions. Example: # this is a single line comment Print - ANSWER A function to display the output of a program. Using the parenthesized version is arguably more consistent. Ex:>> # this will work in all modern versions of Python >> print("some text here")"some text here" The range() function: - ANSWER it returns a list of integers, the sequence of which is defined by the arguments passed to it. Argument variations:- range(terminal)- range(start,terminal)- range(start,terminal,step_size) Example: >> [ i for i in range(4)][ 0, 1, 2, 3]>> [ i for i in range(2, 8)] [ 2, 3, 4, 5, 6, 7] >> [ i for i in range(2, 13, 3)] [ 2, 5, 8, 11] For Loops: - ANSWER Python provides an iteration syntax. Note the colon and indentation.
File writing syntax: - ANSWER myFile.writelines("Data to be written") Ex: # Ask for the input and output files' names inputFileName = input("Input file name: ") outputFileName = input("Output file name: ")
open(outputFileName, "w")
while line != "": outfile.write(line) value = float(line) total = total + value count = count + 1 line = infile.readline()
outfile.write("\n") outfile.write(str(total)) outfile.write("\n")avg = total / count outfile.write(str(avg))