Problem C
Extracting a Number
Write a function extract_first_number_from_string(string_to_search) which takes a string as a parameter. The function should extract the first number from the string and return it as an integer, or return $-1$ if no number was found.
Note that we are testing your code differently in this task, please only submit your function definitions, without any code outside the functions! The main python file, which handles input and output, is already provided. You can download and place the main file in the same directory as your python file. You can then run the main python file we provide to try out the samples.
Input
The input consists of one string which is at least $0$ and at most $100$ symbols, each of which is either a space, a digit or a letter in the English alphabet. Note that this means there will not be any sign (plus or minus) in front of any numbers, only positive integers will be considered. You need not verify this.
Output
The output of the function should be one integer, the first number contained in the input string, or $-1$ if no number was found.
Sample Input 1 | Sample Output 1 |
---|---|
There are 365 or 366 days in the year. |
365 |
Sample Input 2 | Sample Output 2 |
---|---|
These are not the numbers you are looking for. |
-1 |
Sample Input 3 | Sample Output 3 |
---|---|
|
-1 |
Sample Input 4 | Sample Output 4 |
---|---|
Assignment7 is gr8 and all but do check out the extra assignment 2 |
7 |