--Originally published at Programming
Hello everybody.
Today we have questions to practice for the exam. It’s similar to my blog quiz 11, but now complete.
Exercises
We have already done the first part:
1.- See question 2 from Quiz 11
2.- See question 4 from Quiz 11
3.- See question 5 from Quiz 11
4.- Go to Quiz 08
This is new:
5.- Babylonian method
This is like WSQ10, but we can review it again here.
Instructions: Write a function to calculate the square root of a number x using the Babylonian method, it receives a single parameter: the number x and returns the value of the square root of x when two successive estimates differ only by 0.0001 (or less).
Code:
It runs like:
6.- Bananas
This is like WSQ11, but we can review it again here.
Instructions: Write a function called find_bananas which receives a single parameter called filename (a string) and returns a positive integer which is the number of times the word (string) “banana” is found in the file. The banana can be any case (‘BaNana’ or ‘BANANA’ or ‘banana’, etc) and they can be “stuck together” like “banAnaBANANA” (that counts as two). Create your own test file (plain text) to check your work.
Code:
How it runs: