# AI News, Difference between revisions of "How to Think Like a Computer Scientist: Learning with Python 2nd Edition/Solutions"

## Difference between revisions of "How to Think Like a Computer Scientist: Learning with Python 2nd Edition/Solutions"

The following section contains answers to the exercises in the Book.

Why does a call to num_digits(-24) result in an infinite loop (hint: -1/10 evaluates to -1)?

The loop will end when n = 0, and per above -1/10 == -1, causing an infinite loop.

Encapsulate: in a function named count_letters, and generalize it so that it accepts the string and the letter as arguments.

Now rewrite the count_letters function so that instead of traversing the string, it repeatedly calls find (the version from Optional parameters), with the optional third parameter to locate new occurences of the letter being counted.

ceil function finds the lowest integeral value greater than or equal to x.

deepcopy would have come handy in exercises you didn't have to solve regarding object reference, thus no answer is excpected here.

The word 'alice' occurs 386 times (not including 12 occurences of 'alice's')

## String.IndexOf String.IndexOf String.IndexOf String.IndexOf Method

Reports the zero-based index of the first occurrence of the specified string in the current String object.

Parameters specify the starting search position in the current string, the number of characters in the current string to search, and the type of search to use for the specified string.

The following exampledemonstrates three overloads of the IndexOf method that find the first occurrence of a string within another string using different values of the StringComparison enumeration.

The comparisonType parameter specifies to search for the value parameter using the current or invariant culture, using a case-sensitive or case-insensitive search, and using word or ordinal comparison rules.

Note that in the case of the first string, which includes the soft hyphen followed by an &quot;m&quot;, the method fails to return the index of the soft hyphen but instead returns the index of the &quot;m&quot;

Python Find String Method

Be sure to like, share and comment to show your support for our tutorials. ======================================= Channel - ..

Extract Text Between Two Characters in Excel

Like this tip? Find more at ☆ Extract text between two characters in a cell. This video looks at how to extract text between two forward ..

Excel: Find the Position of the First Letter in a Text String

The video explains how to use Excel to find the position of the alpha character in a text string. The formula generated in the video is: {=MATCH(TRUE ...

How to find index of a character or string in java?

get character index string java, find index character string java, character index string java, character at index string java, get character at index of string java, ...

Common Substring Examples and .Length - VB .Net String Functions

In this video I will explain some common applications of the SubString function using Visual Basic 2010. I will explain how to return the end or the beginning of a ...

Excel Magic Trick 531: Extract Numbers from Middle of Text String BB34G to 34 (2 methods)

See two formulas that will remove leading and trailing letters in order to extract a number. BB34G becomes 34. See the functions, INDIRECT, ROW, LEN, ...

Python 3 Programming Tutorial - Multi-line Print

This Python 3 tutorial covers how to do a multi line print statement, with just 1 print function. Sample code for this basics series: ...

Java Program to Find the Count of Occurrences of Each Character in a String

Write a Java Program to Find the Count of Occurrences of Each Character in a String. Well, if you are appearing for any IT company interview this is the most ...

Excel Magic Trick 323: Partial Text VLOOKUP (Fuzzy Match)

Two formulas: VLOOKUP function with wild card criteria for the lookup_value and LOOKUP / SEARCH functions formula with 2^15 number. See what happens ...

C++ Programming 30 - String find function

Examples of the string data type and using the find function.