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

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter7: Developing An Excel Application
Section: Chapter Questions
Problem 3RA
icon
Related questions
Question

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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Concept of Parenthesis
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning