1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mart [117]
3 years ago
15

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.
Computers and Technology
1 answer:
Ksju [112]3 years ago
8 0

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 ( _)

<em>      while userinut[0] == '-' or userinut[0] == '_': </em>

<em>            print(bool(True))  </em><em>->The function returns True</em>

<em>            break; </em>

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

<em>      else: </em>

<em>            print(bool(not True))  </em><em>-> This returns false</em>

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)

<u><em>NB: The program does not make use of if statement</em></u>

You might be interested in
How would you print from 1 to 1000
Hitman42 [59]

Answer:

There are two ways to print 1 to 1000

  1. Using Loops.
  2. Using Recursion.

Explanation:

Using loops

for(int i=1;i<=1000;i++)

{

  cout<<i<<" ";

}

Using recursion

Remember you can implement recursion using a function only.

void print(int n)

{

  if(n==0)

  return;

  print(n-1);

  cout<<n<<" "';

}

you should pass 1000 as an argument to the function print.

5 0
3 years ago
Assume you're using a three-button mouse. To access shortcut menus, you would
irina1246 [14]
If you are using the three-button mouse, in order to access the shortcut menus, you would right click the mouse. 
If you right click your mouse, it will show shortcut menus that can be easily accessed.
5 0
2 years ago
What is an example of a hard skill?
Serjik [45]
3 would be self management
4 0
3 years ago
Read 2 more answers
En una Memoria SD de 128 Gb, ¿Cuántas fotos en alta resolución de 16 Mb puedo almacenar?
fredd [130]

Answer:

Puedes tener 8.

You can have 8.

3 0
2 years ago
What is the simplest way to permanantly get rid of an unwanted file
UNO [17]
If on a computer, if thee computer says they put it in the recycling bin, the go to the recycling bin and right click and delete. If a paper, throw away. If other, do what your body desires to do.<span />
4 0
3 years ago
Other questions:
  • Write the steps for displaying multiple subtotal functions in excel.
    10·1 answer
  • Jessica finds out that the government introduced a new trade policy that will increase import tariffs. She calls for a meeting o
    15·1 answer
  • Pseudocode is a good choice to communicate a____of a process
    10·1 answer
  • What makes someone an expert? What potential issues are there with this?
    10·2 answers
  • Choose all stages of the information processing cycle.
    12·2 answers
  • 6.16 LAB: Find largest number (EO) Write a method, findMax(), that repeatedly reads in integers until a negative integer is read
    9·1 answer
  • Caps lock key is used to type alphabets. _________​
    6·2 answers
  • Please help I will mark brainliest
    5·1 answer
  • Large and fast disks should be used for as doing so will ensure work is done as quickly as possible?
    8·1 answer
  • How does the use of blocking affect the external sorting algorithm, and how does it change the cost formula
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!