Problems regarding string expressions


In this program:

x = 'ajr'
print 'Hello', x, '!'
a space appears between each of the output items; thus the output looks like this:
Hello ajr !

To get rid of the space, we can print a single item which uses string concatenation (which is written with a '+' in Python). Do this.

[solution]


Santa wants a program which says "ho ho ho". Make this string out of a single repetition of the syllable (i.e. a string like "ho", or maybe a bit bigger but not all three copies). An extra space at beginning or end is ok, but there should be exactly one space between the words.

[solution]


This program:

dollars = 12
cents = 34
print '$', dollars, '.', cents
contains unwanted spaces; and the print statement yields incorrect output when "cents" is less than 10 (try it!).

Write a replacement print statement which outputs no spaces and formats the cents correctly.

[solution]


[index of CSC 104 test problem categories]
[main course page]