# Challenge for beginners

 Vaibhav Patel · November 14, 2014 Hai all,I am fairly new to the world of programming.after 2 days of hard work, I created the below code. But I want to add a condition to it. if user input string value as "X" or "Y", the system should throw message saying " Please insert numerical value",if not than the system should produce the result.-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------x = input(int)y = input(int)z = (int(x)+int(y))print ("the sum of ",x,   "and ", y,  "is", z)z = (int(x)-int(y))print ("the difference of ", x , "and" , y , "is ", z)z = (int(x)*int(y))print ("the multiplication of " , x , "and", y, "is " , z)z = (int(x)/int(y))print ("the division of " , x , "and" , y, "is ", z)z = (int(x)%int(y))print ("the remainder of ", x ,"and", y , "is ", z)

## Replies

 Vaibhav Patel · November 14, 2014 Sound a little smaller way to generate same result for the above code.x = input(int)y = input(int)print ("the sum of ",x,   "and ", y,  "is", (int(x)+int(y)))print ("the difference of ", x , "and" , y , "is ", (int(x)-int(y)))print ("the multiplication of " , x , "and", y, "is " ,(int(x)*int(y)))print ("the division of " , x , "and" , y, "is ", (int(x)/int(y)))print ("the remainder of ", x ,"and", y , "is ",(int(x)%int(y))) Doug Fresh · November 21, 2014 Well, you'll want to use a loop in order to check values. Specifically a try/except loop. It will try to complete the actions inside of a loop, they cannot be completed, then the program will display a message, as long as the exception isn't raised, the while loop will break and go on to the next. ``while True:    ## we use a defensive approach so that our values will always return something when we want    try:        ## note the use of int(input to specify the input expected must be an integer.        ## without the try/except loop, python would throw an error, and the program would break                x = int(input("Please enter a numerical value for x: "))    except ValueError:        print("Please enter a number, sucka!")    else:        breakwhile True:        try:        y = int(input("Please enter a numerical value for y: "))    except ValueError:        print("Enter a dang number only. jeez")    else:        breaksome = x+ydifference = x-ymultiply = x*y## If y = 0,  you will get an error.if y == 0:    division = "Error, can't divide by 0"    remainder =  "Error, can't divide by 0"else:    division = x/y    remainder = x%yprint("The sum of {0} and {1}, is {2}.".format(x,y,some))print("The difference of {0} and {1}, is {2}.".format(x,y,difference))print("The multiplication of {0} and {1}, is {2}.".format(x,y,multiply))print("The division of {0} and {1}, is {2}.".format(x,y,division))print("The remainder of {0} and {1}, is {2}.".format(x,y,remainder))``except is used with any conditional statements, or Boolean values.
• 1

## Python

129,996 followers