Related questions
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
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- Function Name: compliments Parameters: answer1 - a boolean (True or False) representing whether the user is "smart" answer2 - a boolean (True or False) representing whether the user is "awesome" answer3 - a boolean (True or False) representing whether the user is "fun" Description: Write a function that outputs a string of compliments based on the adjectives selected by the inputs. Use the inputs True and False. The function should return the string "You are" concatenated with the compliments that are true. The three compliments should be: "smart" "awesome" and "fun". If none of the compliments are true, print the string "Goodbye." instead. Test Cases: >>>compliments(True, True, True) You are smart awesome fun. >>>compliments(False, True, False) You are awesome. >>>compliments(False, False, False) Goodbye.arrow_forwardParameters are the value passed to a function when the function is called and Argument are the variable defined in the function definition. True or falsearrow_forwardWhen a function accepts several arguments, how important is it what order they are sent in?arrow_forward
- # Exercise 8: Create a function that takes the sum of three numbers and returns the value # Make sure to use the function and display the result # When you are done, get 3 numbers from a user and then print out the sum using your functionarrow_forwarder 6 Functions Programming Exercises te 1. Rectangle Area ngle Area The area of a rectangle is calculated according to the following formula: Area = Width X Length Design a function that accepts a rectangle's width and length as arguments and returns the rectangle's area. Use the function in a program that prompts the user to enter the rectangle's width and length, and then displays the rectangle's area.arrow_forwardComplete the following Codearrow_forward
- Instructions The python "try" keyword is very powerful in that it can, among other things, prevent a program from ending abnormally because of invalid numeric input. Write a python program with two functions/modules that does the following: .main() accepts input and calls a function to test if the input is a number and displays a message regarding the result of that numeric test • numTest() is passed an input string, tests to see if the string is numeric and returns the necessary information to main() . a NULL input (just pressing the enter key) ends the program . DO NOT USE THE BUILTIN PYTHON FUNCTION FOR NUMERIC TESTING Be sure to use clear prompts/labeling for input and output.arrow_forwardPHYTONarrow_forwardLogical variables: On Time or Delayed? Complete the function WhatlsIt such that: The output logical variable on Time is true only if no Traffic is true and gasEmpty is false. The output logical variable delayed is false only if no Traffic is true and gasEmpty is false. Restriction: Logical expressions must be used. Do not use if statements. Function> 1 function [onTime, delayed] = WhatIsIt (noTraffic, gasEmpty) 2 onTime = 3 delayed = 4 5 end Save C Reset MATLAB Documentationarrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education