Does a String Represent an Integer
Problem Description
In this exercise you will write a function named isInteger that determines whether or not the characters in a string represent a valid integer. When determining if a string represents an integer you should ignore any leading or trailing white space.
Once this white space is ignored, a string represents an integer if its length is at least 1 and it only contains digits, or if its first character is either + or - and the first character is followed by one or more characters, all of which are digits.
Write a main program that reads a string from the user and reports whether or not it represents an integer. Ensure that the main program will not run if the file containing your solution is imported into another program
Refer sample input and output for formatting specification.
All float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
CODING ARENA
a=input()
if a.isnumeric():
print("Contains Integer")
else:
print("Does not Contain")
Test Case 1
Input (stdin)eLab
Expected Output
Does not Contain
Test Case 2
Input (stdin)2017
Expected Output
Contains Integer
No comments:
Post a Comment