0
#if we put an alphabet in 'x' it should loop infinite times

x = str(input("put number here: "))

so I wanna loop x statement in python if we put an alphabet in x and I've been at it for the past month but all i'm getting is for loop and those continue loops, I've tried them but they don't work (at least with my brain) so please some help would be appreciated.

  • 1
    Please update your question with one example of code you have tried and a sample input you would supply and the expected output. – quamrana Sep 24 '22 at 12:08
  • 1
    `input` already returns a string; calling `str` on the returned value doesn't do anything. (IIRC, `str` just returns its argument when it's a `str`, rather than creating a new string: `str` values are immutable, so creating a copy makes no sense.) – chepner Sep 24 '22 at 12:17
  • 1
    Do the answers to this [question](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) help at all? – quamrana Sep 24 '22 at 12:20

1 Answers1

0

I'm not sure I've got you right
but maybe you're looking for something like this:

while variable := input("put number here: "):
    if not variable.isalpha():
        break

this code places user's input inside variable and do it only if input is not [a-zA-Z]

Dmitriy Neledva
  • 867
  • 4
  • 10