Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROBLEM 1 This python program will test your ability to examine and manipulate strings. Create a file named Lab 0 7 P 1 . py

PROBLEM 1
This python program will test your ability to examine and manipulate strings.
Create a file named Lab07P1.py. Write a program that does the following:
Use a loop to ask the user to enter a series of IP addresses in a specific format: ###.###.###.###. For example, 192.168.0.1.
You will need to validate that the IP address is in the correct format. Check for these validation conditions IN THIS ORDER:
Check whether the user entry has exactly three periods. If it doesn't, display an appropriate error message and continue in the loop. Do not check on other error conditions.
Check whether each part of the IP address is a number. If any part is not a number, display an appropriate error message and continue in the loop without checking other error conditions.
Check whether each number in the IP address is between 0 and 255 inclusive. If any number is not, display an appropriate error message and continue in the loop without checking other error conditions.
If the IP address entered was valid, then change the periods to colons and display the newly formatted IP address.
For example, if the IP address was: 192.168.0.1
...the program should display: 192:168:0:1
The program will continue asking the user for IP addresses until they enter a q or Q to exit the program.
Here's pseudocode to help you solve this problem:
# Ask the user to input an IP address or 'Q' to quit
# while the user has not entered 'Q' or 'q' to quit
# split the user input at each period and store the parts in a list
# if there are not 4 parts in the list
# display an error message
# else
# set error flag to False
# for each part in the list
# if the part is not a number or if it is not between 0 and 255
# display an error message
# set error flag to True
# break the loop
# if no error has been displayed (i.e., error flag is False)
# replace each period in the user input with a colon
# display the new formatted IP address
# ask the user to input an IP address or 'Q' to quit
You may want to consider copying the above pseudocode into your Python file and use it as comments that can also guide you as you write this program.
Sample output:
Please enter an IP address or 'Q' to quit: 122.44.33
Error: An IP address should consist of 4 parts separated by periods.
Please enter an IP address or 'Q' to quit: 122.44.33.x
Error with x: Each part of the IP address should be a number between 0 and 255.
Please enter an IP address or 'Q' to quit: 122.444.33.x
Error with 444: Each part of the IP address should be a number between 0 and 255.
Please enter an IP address or 'Q' to quit: 122.44.33.89
Reformatted IP address: 122:44:33:89
Please enter an IP address or 'Q' to quit: q
Submit the program file Lab07P1.py to Blackboard for credit.Sample output:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions