Traverse and Repeat Alphabets Sequence until "N" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Traverse and Repeat Alphabets Sequence until "N"

Hi!! What I mean with the title is like this, I have 2 problem: FIRST: there are 26 alphabets from a to z and given a value of "N" to traverse and print the list of alphabet. For example: 1) N = 26, output will be from a to z because z is the 26th alphabet 2) N = 5, output will be from a to e because e is the 5th alphabet 3) N = 30, output will start from a to z and then will continue print from a and then to d, because this d is known as the 30th alphabet So if N is over 26, it will continue print from the first alphabet, which is a and keep continue until it reaches the N th alphabet SECOND: Let's just say our code stop at D and when we want to use the code again, it will start where we left off which is D and our code will just print E until the N th alphabet Here's my code link: https://code.sololearn.com/cmnO3arI2oG6 And here's what I mean for second problem: https://stackoverflow.com/questions/21594302/is-there-a-way-to-remember-the-position-in-a-JUMP_LINK__&&__python__&&__JUMP_LINK-iterator My solution on first problem imo is not efficient enough and I still don't know the solution for second problem. So could you help me on solving this or giving tips? Any help is appreciated. THX!!!!

4th Sep 2021, 2:47 PM
M.O.HONOR
M.O.HONOR - avatar
3 Answers
+ 3
second problem solution is given on stack itself! M.O.HONOR you code also works just don't print character inside the loop.. I stored all the characters in a variable and display it outside the loop see here : https://code.sololearn.com/c205tjogvSn0/?ref=app here is my solution: https://code.sololearn.com/cvkvZZ65A0jr/?ref=app
4th Sep 2021, 3:29 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 3
I would use the help of modulo operator for the first problem. Can you share that code in Description? saying "not efficient enough" without a code for review is kinda intriguing. Didn't clearly get the idea of that second problem, so I guess I'll just wait for your code link. In case you didn't know how to attach a code link ... https://www.sololearn.com/post/75089/?ref=app (Edit) My try https://code.sololearn.com/cR4OUrjWuA9O/?ref=app
4th Sep 2021, 3:23 PM
Ipang
0
While waiting for your code, here’s a possible solution: import string def printAlpha(n): alphab = string.ascii_lowercase while n > len(alphab): alphab = alphab + alphab[:n-len(alphab)] print(alphab[0:n]) n = int(input()) printAlpha(n)
4th Sep 2021, 3:26 PM
DavX
DavX - avatar