Multiplying strings

Computer Science Level pending

Great! Now you want to print a dotted line below the message for Aditya, so that you can eventually print messages for several students on the same page, and easily cut along the dotted line to separate the messages. You're just doing your part to save the planet.

You write the following code:

1
2
3
4
5
6
7
8
9
name = "Aditya"
score = 98
liked = True

message = "Hi %s. You achieved a score of %d." % (name, score)
extra = "It's %s that I enjoyed having you as a student." % liked

print message, extra
print [---]

What do you use to replace [---] so that you get a row of 80 - with no spaces in between? Your output should like like this:

1
2
Hi Aditya. You achieved a score of 98. It's True that I enjoyed having you as a student.
--------------------------------------------------------------------------------

'----'*20 '-'*80 Neither '-' 80 nor '----' 20 will work because you cannot use * to multiply strings. Both '-' 80 and '----' 20 will work

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Strings can be concatenated using the + + operator and repeated using the * operator.That's why both '-' 80 and '----' 20 will work.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...