Define a function begins_with_line that consumes a string and returns a boolean indicating whether the string begins with a dash ('-') or a underscore '_'. For example, the string "-Yes" would return True but the string "Nope" would return False. Note: Your function will be unit tested against multiple strings. It is not enough to get the right output for your own test cases, you will need to be able to handle any kind of non-empty string. Note: You are not allowed to use an if statement.

Respuesta :

Answer:

The program written in python is as follows:

def begins_with_line(userinut):

     while userinut[0] == '-' or userinut[0] == '_':

           print(bool(True))

           break;

     else:

           print(bool(not True))

userinput = input("Enter a string: ")

begins_with_line(userinput)

Explanation:

The program makes use of no comments; However, the line by line explanation is as follows

This line defines the function begins_with_line with parameter userinut

def begins_with_line(userinut):

The following italicized lines checks if the first character of user input is dash (-) or underscore ( _)

     while userinut[0] == '-' or userinut[0] == '_':

           print(bool(True))  ->The function returns True

           break;

However, the following italicized lines is executed if the first character of user input is neither dash (-) nor underscore ( _)

     else:

           print(bool(not True))  -> This returns false

The main starts here

The first line prompts user for input

userinput = input("Enter a string: ")

The next line calls the defined function

begins_with_line(userinput)

NB: The program does not make use of if statement