Create a week09 subdirectory in your cs21/class directory and copy over my starting point files:
$ cd $ cd cs21/class $ pwd /home/your_user_name/cs21/class $ mkdir week09 $ cd week09 $ pwd /home/your_user_name/cs21/class/week09 $ cp ~newhall/public/cs21/week09/* .After class, you can copy over my files by doing:
$ cp ~newhall/public/cs21/week09/tia* .
print "format string with special place holders for values" %(argument list)For example:
print "an int value: %d, a float: %f, a string: %s" %(23, 9.8, "hello")outputs:
an int value: 23, a float: 9.800000, a string: helloThe %d, %f, and %s in the format string are place holders for an int, a float, and a string value, and each gets replaced with its corresponding value from the argument list %(23, 9.8, "hello") in what print outputs.
Using formatted string form of print statements is sometimes more convenient than having to list: string, value, string, value, ...:
print "an int value", 23, "a float", 9.8, "a string", "hello"The real advantage of using formatted print statements is that you have much more control over print's output. For example, the formatted print statement:
print "%10s \t %5d \t %5.2f" %(sval, ival, fval)prints out a string value in a field width of 10 characters wide, then a tab character, then an int value in a field of 5 characters wide, then a tab character, and then a float value in a field of 5 characters wide with a precision of 2 places beyond the decimal point.
This is very useful is you want to line up tabular output and some of the numerical values that you are printing out have different numbers of characters, or if you want to print a differnt precision of floating point values than the default.
Take a look at other examples in this file, and try running it to see what the formatted print statements do.