Restricting an input value to only strings without using the function str()

Does anyone know how to restrict my input values to only strings without using the str() function?
I am trying to restrict the input to only strings using the while statement

Why would you want to disallow numbers? What if the user’s sentence contains a number?

That’s a good point, I did not think about that.
Is there a way to still do it even if the sentence includes a number?

you just don’t want to see a number ever? Try using not my_input.isDigit()

you mean isdigit()

btw str.isdigit() returns False if there’s any non-digit characters in the string

also btw @jonathanessombe input always returns a string even when the user just inputs a number

2 Likes

Does .isdigit accept an arguement? if it does what does it do?

1 Like

No, str.isdigit() does not accept any arguments (what would be the point of them?)

1 Like

@jonathanessombe why did you mark my post as the solution? Did you solve your problem? If so, how?

lol, I thought I solved the problem, i guess i didn’t.
This is what i have so far

Well you’re testing if string_length is equal to True/False, but you either return 'please enter a valid string!' or the length of the given string.

1 Like

thank you, i just realized the mistake

I keep getting an assertion error for line 11, do you think you know where i went wrong?

"hi 98".isdigit() is False because not all characters in it are digits.

I don’t know if i need seperate post about it but is there a way to differentiate between a string containing a digit vs just a string?

def has_digit(string):
  for char in string:
    if char.isdigit():
      return True
  return False
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.