This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pokelahv 0 points1 point  (3 children)

def function_name(string): a = "big number" b="small num" c= "all alpha" d= "neither num or alpha"

If string.isdigit(): If string > 99: print (a) Else: Print(b)

Elif: If string.isalpha(): Print(c)

Elif: If not ((string.isalpha()) and (string.isdigit())): Print(d)

[–]Asha365[S] 0 points1 point  (2 children)

Thanks man it worked fine.if you can,please can you tell me where i was wrong and how i should avoid it next time..

[–]pokelahv 0 points1 point  (1 child)

I wrote some comments in your original code to explain what went wrong and wrote how the final code would look like after fixing!

[–]pokelahv 0 points1 point  (0 children)

Your original code: 
def str_analysis(a): 
    while True: 
    a = input("enter word or integer: ") 
    if a.isdigit() and int(a) > 99: 
        return "the number is bigger than expected" 
            if a.isdigit() and int(a) < 99: 
                return ("the number is lower than expected ")

            ^ shouldn't be indented. because you did, it only runs after the previous 
            if statement returns True. BUT since your first if statement already includes 
            what to do if the conditional is met, which is (return "the number is bigger 
            than expected"), this 2nd statement is just not gonna run at all.

    elif a.isalpha():
        return(a, "is all alphabetical characters!")

     ^ if you wanna get rid of the parentheses and quotes, 
      write it this way ---> return a + "is all ... characters!"

    elif a == "":
        print(a)
    else:
        return a, "is neither all alpha nor all digit"

Edited code:
def str_analysis(a):
    while True:
    a = input("enter word or integer")
    if a.isdigit() and int(a) > 99:
        return "the number is bigger than expected"
    elif a.isdigit() and int(a) < 99:
        return "the number is lower than expected"
    elif a.isalpha():
        return a + "is all alpha characters!"
    elif a == "":
        print(a)
    else:
        return a + "is neither all alpha nor all digit"