Is this a Phone Number? Learning Objectives In this lab, you will Create a function according to the specifications Use nested if/else statements Instructions Write a function, isPhoneNumber(digits), that checks to see if the input is a real phone number. This function should: Return True if 'digits' is type int and is 10 digits long Otherwise, returns False You can use the assert statements to test that your function behaves as expected. Hint: You can confirm 'digits' is an int with type(digits) == int Hint: To check the length of the number, you can convert it to a string first, then check the length. Alternatively, you can use integer division. # Define the function isPhoneNumber() below. The function should: # - Check that the input value has type 'int' and is 10 digits long. # - If this is true, return True # - If this is false, return False def isPhoneNumber(digits): pass # No print statement is needed for submission, but you can use a print statement to # confirm the output of isPhoneNumber(digits) is as expected with various inputs . if __name__ == "__main__": assert isPhoneNumber("1234567890") == False assert isPhoneNumber(1234567890) == True
Is this a Phone Number?
Learning Objectives
In this lab, you will
- Create a function according to the specifications
- Use nested if/else statements
Instructions
Write a function, isPhoneNumber(digits), that checks to see if the input is a real phone number. This function should:
- Return True if 'digits' is type int and is 10 digits long
- Otherwise, returns False
You can use the assert statements to test that your function behaves as expected.
Hint: You can confirm 'digits' is an int with type(digits) == int
Hint: To check the length of the number, you can convert it to a string first, then check the length. Alternatively, you can use integer division.
# Define the function isPhoneNumber() below. The function should:
# - Check that the input value has type 'int' and is 10 digits long.
# - If this is true, return True
# - If this is false, return False
def isPhoneNumber(digits):
pass
# No print statement is needed for submission, but you can use a print statement to
# confirm the output of isPhoneNumber(digits) is as expected with various inputs .
if __name__ == "__main__":
assert isPhoneNumber("1234567890") == False
assert isPhoneNumber(1234567890) == True
![1: Test isPhoneNumber(4243137890) returns True ^
0/1
Test isPhoneNumber(4243137890) returns True
Test feedback
isPhoneNumber (4243137890) incorrectly returned None
2: Test isPhoneNumber(3109216754) returns True ^
0/1
Test isPhoneNumber(3109216754) returns True
Test feedback
isPhoneNumber (3109216754) incorrectly returned None
3: Test isPhoneNumber(243137890) returns False ^
0/1
Test isPhoneNumber(243137890) returns False
Test feedback
isPhoneNumber (243137890) incorrectly returned None
4: Test isPhoneNumber('sandwiches') returns False a
0/1
Test isPhoneNumber('sandwiches') returns False
Test feedback
isPhoneNumber ('sandwiches') incorrectly returned None](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F65d4b7c1-bff9-4699-bca1-37915a859545%2F015e4e0c-2e0d-4e66-b9ff-5e9a0fab5a0c%2Fl74gt3j_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)
![Programming with Microsoft Visual Basic 2017](https://www.bartleby.com/isbn_cover_images/9781337102124/9781337102124_smallCoverImage.gif)