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 +'\n'*number+ln)
print(fn+'\t'+ln)
print(fn*number)
print(f'The sentence is {para}')
if __name__ == '__main__':
fn = input()
ln = input()
para = input()
no = int(input().strip())
stringoperation(fn, ln, para, no)
Have done the same thing.
ReplyDeleteMy output and expected osutput is the same.
But it says i have failed all the hackerrank test cases..
any suggestions as to why that would be?
Awesome article post.
ReplyDeleteP0wer bi onlinetraining from india
P0wer bi onlinetraining
Awesome article post.
ReplyDeleteP0wer bi onlinetraining from india
P0wer bi onlinetraining
nice post.
ReplyDeleteP0wer bi onlinetraining from india
P0wer bi onlinetraining