For example,
classes = ['CS 1510', 'CS 1520', 'CS 2530']
list_to_file(classes, 'schedule.txt')
will write three lines to a file named
schedule.txt.
def f(x, y, z):
...
return total
List the steps that occur when the statement var = f(a, 2, int(arg)) is executed.
>>> sum_of_digits(1984)
22
Recall that we can separate a number into its last digit and the rest of its digits using % and //, respectively.
def mystery(x, z, y):
x = x + y
y = y + z
return y * z
x = 1
y = 3
z = 2
x = mystery(z, x, y)
print(x, y, z)
>>> unique([1, 2, 1, 2, 3, 1, 4, 2, 3, 4])
[1, 2, 3, 4]
def empty_grid(rows, cols):
grid = []
row = []
for i in range(cols):
row.append(0)
for i in range(rows):
grid.append(row)
return grid
This function does create a grid of independent cells, as expected.
>>> choice = get_selection(1, 4)
Enter value between 1 and 4: 6
Sorry, 6 is not in range.
Enter value between 1 and 4: 0
Sorry, 0 is not in range.
Enter value between 1 and 4: 3
>>> print(choice)
3
> wc card-exercise.txt
13 448 2572 card-exercise.txt
Write a Python function named counts that takes a file as an argument (not a filename) and returns a tuple containing the number of lines, words, and characters in the file.
With your function, we can implement wc with this code:
lines, words, characters = counts( text_file )
print('{:8d}{:8d}{:8d} {:s}'.format(lines, words, characters, filename))