+ 2
letter pattern python
https://www.sololearn.com/compiler-playground/c1Aib1aN4z11 I want it looks like this: A B C D E F G H I J K L M N O
11 Answers
+ 4
def alphapat(n):
num = 65
for i in range(0, n):
for j in range(0, i+1):
ch = chr ( num )
print(ch , end=" ")
num = num + 1 #inside inner loop.
print("\r")
n = 5
alphapat(n)
+ 4
Bob_Li '\r' is a carriage return escape character it works differently on different operating system.
On linux it works like backspace but on windows it works similar to '\n' i.e. new line character
+ 2
Jayakrishna🇮🇳
cool code😎
I never understood what print('\r') does, though. print() seems to work ok.
Btw, did Sololearn add a codeblocker in the reply form? I get this no connection message and cannot submit when my reply contains code...
But you obviously can do it.
very strange.🤔
and if I copy paste your code, i can submit it.
even stranger.😲😲
Anyway, I made some modification in your code to keep the range in the capital letters if n is large.
https://code.sololearn.com/c7uC5oK2O14W/?ref=app
+ 1
Its start from b when i add it inside inner loop Jayakrishna🇮🇳
+ 1
Bob_Li
As @Snehil said, '\r' is carriage return works depends on operating system. Here it won't work. Am not added it. OP trying it in System. So it it works there.. I just edited code to work it properly as expected output.
Also yes, I faced same trouble and find that chr function is blocking to add code so added a space=> chr () . Reason I don't know, I already asked Sololearn staff and other senior mentors and waiting for their response.
+ 1
❓❓chr ()❓❓
or
gvhgvvbhvbvg chr ()hhbvgcv
Jayakrishna🇮🇳 you are right. remove the space between 'chr (' and it blocks.
also the chr must have a space before it.
+ 1
Bob_Li Yes. Trying without a space between, it's blocking.
0
Add num += 1 inside inner loop. Not after..
0
some trouble in replying... pls wait.
0
STOP done.
Faced trouble in adding..
0
Hii