top of page

Week 3: Functions, structures and loops

With the first task in Week 3 i had to try different in built methods (for strings mainly). The task was to write a script to complete each of the following tasks. The challenge was working out the name of the function and how to call it. You can use theinteractive help system or the Python documentation (online or oine).(a) Reverse all the elements in the list[True, False, True, True, False].

(b) Insert"John"into the list["George", "Paul", "Ringo"]as the second element.

(c) Remove the value"15"from this list[2,3,5,7,11,13,15,17,19]. There are two ways to do this:one by value and one by index. Discover them both.

(d) Convert all letters in the string "GOod Morning" to lowercase.

(e) Centre the word "Title" in a string of length 44.(f) Split the string "This is a string" up into a list of the individual words.

(g) Remove thehttp://from"http://www.coventry.ac.uk"

Here is the solution to the problem:

The second task was to ask the user for width and length input and create a tree out of '*' symbols from these inputs. Here is the solution

Here we start with the more advanced tasks. The next one is to write the Newton's method for calculating square roots incrmentally.

The last task i did was to implement he Sieve of Eratosthenes method. This is a method for finding all prime numbers below given integer. The idea is to eliminatenumbers which are multiples of known primes. So we start with 2; accept it is prime; rule out all itsmultiples (4,6,8,. . . ); repeat for 3; then 5 (skipping 4 since it has already been ruled out). The script i need to write is to find all prime numbers below 500.

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square

Email:
kabadzhg@uni.coventry.ac.uk

bottom of page