Hello everyone and welcome to this new python tutorial !!!
Today’s videos is about some things that I found really interesting in controlling strings!!
The first set method that we goanna check out is of knowing if the provided string character is a number or letter !
The second set of methods is to convert alphabetic characters to numeric code and vice versa.
To explain this or to put is application, we will try to build a counter that understands if the input is a letter or number and then and continue the count in this criteria
So without futher due lets dive in;
Out first methods are the “isdigit()” and “isalpha()”
And now that we understood how to differentiate between letters and numbers
Lets create the counter!!!
- For the numbers there is no problems, we ll just create a loop
- For the second part where the input is a letter,,,, there where it gets tricky
First we will use the ord() function to get the character code
And now that we got a number there is no problem
Lets create a normal loop and within this loop we will convert the number back to a letter
One final step is to insure that when the counter reaches “Z” it will restart back to “A”
start_str= input("enter a number or a letter to start counting \n")
steps=int(input("enter number of steps \n "))
for c in (range(counter, counter+steps)):
for l in range(counter, counter+steps):
print(chr(counter) + " is " + str(counter ))
if counter == 91:
elif counter ==123: