0
# Validating for only numbers in python one after another(in sequence)

a = raw_input()

#if a is a number then it should take next raw_input i.e., 'b' else it should ask for 'a' again

b = raw_input()

#if b is a number then it should take next raw_input i.e., 'c' else it should ask for 'b' again

c = raw_input()

#if c is a number then it should take next raw_input i.e., 'd' else it should ask for 'c' again

## This should be done upto 'e'
Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
Annas Lee
  • 13
  • 2

2 Answers2

1

use a.isdigit() to validate string a is digit or not

str.isdigit() Return true if all characters in the string are digits and there is at least one character, false otherwise.

Haifeng Zhang
  • 30,077
  • 19
  • 81
  • 125
0

Make use of if..else construct for the conditional checks and refer this post for the integer check.

Edit 1

I have not executed it,but you could try the following and see if it works-

def ask(text):
    temp = raw_input(text)
    try:
        retVal = int(temp)
        return retVal
    except ValueError:
        return False

a = False
b = False
c = False

while not a:
    a = ask("Enter A:")
    if a == False:
        continue
    while not b:
        b = ask("ENter B:")
        if b == False:
            continue
        while not c:
            c = ask("Enter C:")
Community
  • 1
  • 1
Mayur Buragohain
  • 1,566
  • 1
  • 22
  • 42