0

I am a beginer in python and I have a homework and I am stuck a little. The user needs to make an input and if the input is not string, the user needs to make another input for so long until the input is string. First I need to make an input and then check what kind of input it was but then I dont know how to make it possible for the user to make another input. Thank you in front!

The code I started with:

name = input ("Imput the name: ")
if name != str:
    print ("The input name needs to be string!")
Austin
  • 25,759
  • 4
  • 25
  • 48
Matic1295
  • 13
  • 2
  • you can't be using both `python3.x` _and_ `python2.7`. which is it? – wpercy Apr 10 '19 at 17:16
  • Please show an example of your code progression. We need to determine what you have attempted to help you along without just giving you the code. – ShadowMan Apr 10 '19 at 17:17
  • name = input ("Imput the name: ") if name != str: print ("The input name needs to be string!") – Matic1295 Apr 10 '19 at 17:20
  • @Matic1295 by string you mean input should contain alphabetic characters? – sahasrara62 Apr 10 '19 at 17:20
  • Yes. And then I have a same example for integers. If a input is not a number the user needs to make another input until the input is number. – Matic1295 Apr 10 '19 at 17:25

1 Answers1

3

when data (input) is alphabetic characters

data = input()
val = True
while val:
    if data.isalpha():
        print('given input is correct string')
        val = False
    data = input()

when data (input) is an integer value

data = input()
val = True
while val:
    if data.isdigit():
        print('given input is correct numbers')
        val = False
    data = input()
sahasrara62
  • 10,069
  • 3
  • 29
  • 44