- 1

PLEASE HELP WITH THIS.

Consider the string BANANA and print the string in the following format: B B A B A N B A N A B A N A N B A N A N A Input Format: Enter the number of lines of the format to be printed : n (if n=4) Output Format : B B A B A N B A N A Sample Input: 6 Sample Output: B B A B A N B A N A B A N A N B A N A N A MY CODE: a=input() n=input() for i in range(0,n): for j in range(0, i+1): if (n==4): print(a[j],end=" ") print()

11th Jan 2022, 3:21 AM
Saurav Singh
Saurav Singh - avatar
4 Answers
+ 4
#try this a=input() n=int(input()) for i in range(0,n): for j in range(0, i+1): print(a[j],end=" ") print()
11th Jan 2022, 4:37 AM
Simba
Simba - avatar
+ 3
b="B a n a n a".upper() for i in range(len(b)): print(b[0: i+1])
11th Jan 2022, 4:57 AM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 1
Input() returns a string, you must use int() to convert it to a number: n= int( input() ) Also you have a logic problem, what is that if supposed to do?
11th Jan 2022, 3:44 AM
CGM
CGM - avatar
11th Jan 2022, 7:50 AM
Shadoff
Shadoff - avatar