Question

On Python 3.7.2: How would I make functions for these string functions/methods without using the actual...

On Python 3.7.2:

How would I make functions for these string functions/methods without using the actual functions?

(For example, how would I find if a string is comprised of alphabets without using the function "isalpha()" ?)

len()

isalpha()

isupper()

isdigit()

swapcase()

string_lower()

0 0
Add a comment Improve this question Transcribed image text
Answer #1

OUTPUT :

CODE :

def len(x):
ans = 0
for c in x:
ans+=1
return ans

def isalpha(x):
for c in x:
if not ((c>='a' and c<='z') or (c>='A' and c<='Z')):
return False
return True

def islower(x):
for c in x:
if not (c>='a' and c<='z'):
return False
return True

def isupper(x):
for c in x:
if not (c>='A' and c<='Z'):
return False
return True

def isdigit(x):
for c in x:
if not (c>='0' and c<='9'):
return False
return True

def swapcase(x):
ans = ''
for c in x:
if isupper(c):
ans = ans + chr(ord(c)+32)
elif islower(c):
ans = ans + chr(ord(c)-32)
else:
ans = ans+c
return ans

def string_lower(x):
ans = ''
for c in x:
if isupper(c):
ans = ans + chr(ord(c)+32)
else:
ans = ans+c
return ans
  

Add a comment
Know the answer?
Add Answer to:
On Python 3.7.2: How would I make functions for these string functions/methods without using the actual...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT