Python - String Operations - 1
Define a function 'stringoperation' that takes four parameters, namely 'fn', 'ln', 'para' as a string, and 'number' as an integer. The function definition code stub is given in the editor. Generate the print statements based on the condition given as follows:
- First print: concat 'fn', 'number' times the number of newline character and 'ln'
- second print: 'concat' 'fn', tab space and 'ln'
- Third print: Prints the 'number' multiples of the string 'fn'
- Fourth print: Prints the 'para' string using f-string as follows:
*The sentence is {para}
Input Format for Custom Testing
The input from stdin will be processed as follows and passed to the function
- The first line contains a string 'fn', the first name.
- The second line contains a string 'ln', the last name.
- The third line contains a string which contains a paragraph of words.
- The fourth line contains an integer 'number'.
Sample Case 0
Sample Input
STDIN Function ----- -------- Abigail → fn = Abigail joseph → ln = joseph I am a creator → para = I am a creator 3 → number = 3
Sample Output
Abigail
joseph
Abigail joseph
AbigailAbigailAbigail
The sentence is I am a creator
Answer:
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'strng' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. STRING fn
# 2. STRING ln
# 3. STRING para
# 4. INTEGER number
#
def stringoperation(fn, ln, para, number):
# Write your code here
print(fn+number*'\n'+ln)
print(fn+'\t'+ln)
print(number*fn)
print(f'The sentence is {para}')
if __name__ == '__main__':
fn = input()
ln = input()
para = input()
no = int(input().strip())
stringoperation(fn, ln, para, no)
For more clarification click on the image:
No comments:
Post a Comment
If you have any doubts, Please let us know.