What is the output of the below program?
def say(message, times = 1):
print(message * times)
say('Hello')
say('World', 5)
Answers
Answered by
3
Explanation:
say(message,times =1)
Answered by
0
Concept:
A function includes a collection of programming statements and in Python, it is declared with the keyword 'def'.
Given:
def say(message, times = 1):
print(message * times)
say('Hello')
say('World', 5)
Find:
What is the output of the given program?
Solution:
The * operator is used to make a string repeat itself a specified number of times.
Syntax: string * n
(The string is repeated as many times as n specifies.)
By default, the value of times is set to 1. Therefore it prints the string only one time if the value is not given.
∴ say("Hello") will print Hello only one time.
In say("World", 5), the value of times is set to 5. Therefore, it will repeat World 5 times.
Output:
Hello
WorldWorldWorldWorldWorld
Similar questions
English,
2 months ago
Hindi,
2 months ago
Chemistry,
2 months ago
Political Science,
5 months ago
Math,
11 months ago
India Languages,
11 months ago