No error catching, so for some reason, typing "sd" instead of a number gives some crazy errors (details below) unless I add "sd = ' ' " at the start.
As Grumblesaur pointed out, input returns a string, so why if I enter "sd", does it crash out?
This is the working code - copy/paste - run in python, it works for numbers only.
Code: Select all
# Next version use case statements to ask what store you want
# Provide a list of the available stores
print ""
Store_IP = '10.25.'
# This is for testing of "sd" being entered for Third and Fourth
# sd = ''
def Create_IP_Address(Store_IP, Third, Fourth):
# print Store_IP + Third + "." + Fourth
print "Your IP Address is %s%s.%s" % (Store_IP, Third, Fourth)
def main():
Third = input("Enter the 3rd octet: ")
Fourth = input("Enter the 4th octet: ")
print ""
# raw_input on it's own acts like a pause
# raw_input("Press ENTER to continue. . .")
# print ""
Create_IP_Address(Store_IP, Third, Fourth)
print ""
main()
Code: Select all
P:\>python IPAddress-Ver-3.py
Enter the 3rd octet: sd
Traceback (most recent call last):
File "IPAddress-Ver-3.py", line 24, in <module>
main()
File "IPAddress-Ver-3.py", line 15, in main
Third = input("Enter the 3rd octet: ")
File "<string>", line 1, in <module>
NameError: name 'sd' is not defined
P:\>python IPAddress-Ver-3.py
Enter the 3rd octet: 23
Enter the 4th octet: sd
Traceback (most recent call last):
File "IPAddress-Ver-3.py", line 24, in <module>
main()
File "IPAddress-Ver-3.py", line 16, in main
Fourth = input("Enter the 4th octet: ")
File "<string>", line 1, in <module>
NameError: name 'sd' is not defined
Code: Select all
P:\>python IPAddress-Ver-3.py
Enter the 3rd octet: 23
Enter the 4th octet: sd
Your IP Address is 10.25.23.
Code: Select all
P:\>python IPAddress-Ver-3.py
Enter the 3rd octet: 23
Enter the 4th octet: 45
Your IP Address is 10.25.23.45