-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_integer.py
36 lines (30 loc) · 964 Bytes
/
is_integer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
This function reads in a string of characters and determines whether
it contains valid integer.
Input: String
Output: String
"""
def is_integer(string):
# Make sure value is provided.
if len(string) != 0:
# Remove white spaces before processing.
string = string.strip()
# Accomodate signed integers.
if string[0] in ['+', '-']:
if string[1:].isdigit():
display = f'{string.strip()} is an integer'
else:
display = f'{string.strip()} is not an integer'
else:
if string.isdigit():
display = f'{string.strip()} is an integer'
else:
display = f'{string.strip()} is not an integer'
else:
display = f'Invalid input!'
return display
if __name__ == '__main__':
# Request for user input.
string = input("Enter a value: ")
# Display relevant information.
print(is_integer(string))