Hello to everyone !
I have this requirments to make a code and i don’t understand where I am wrong.
In the body of the str_analysis() function:
Check if string is digits
if digits: convert to int and check if greater than 99
if greater than 99 print a message about a “big number”
if not greater than 99 print message about “small number”
check if string isalpha then (since not digits)
if isalpha print message about being all alpha
if not isalpha print a message about being neither all alpha nor all digit
call the function with a string from user input
Run and test your code before submitting
str_analysis (answear):
x = ""
while x != "":
if x.isdigit():
return True
if int(x) > 99:
print ("WoW this is a big number")
if x.isalpha():
print ("This is a word with alphabetical characters")
else:
print("Try again is a small number")
else:
print("not an alpha or digit character")
user_input=input("Enter a word or a number\n")
print(str_analysis(user_input))
I used the while loop because is another requirment. The program will call str_analysis() with a string argument from input collected within a while loop. The while loop will test if input is empty (an empty string “”) and continue to loop and gather input until the user submits at least 1 character (input cannot be empty).
def str_analysis (answear):
if answear.isdigit():
if int(answear) > 99:
print (user_input,"is a pretty big number")
else:
print(user_input,"is a smaller number than expected")
if answear.isaplpha():
print ("This is a word with alphabetical characters")
else:
print("not an alpha or digit character")
user_input=input("Enter a word or a number\n")
while user_input == "":
user_input=input("input can't be empty, enter a word or a number\n")
print(str_analysis(user_input))
i would make it elif answear.isaplpha():, given there is no point in checking if its alpha after checking its digit, but not sure yet why you get the error
I made a lot of mistakes
This program requires the use of
while loop to get non-empty input
if, else
if, else (nested)
.isdigit() check for integer only input
.isalpha() check for alphabetic only input