Killer Web Development

by Marco Laspe

6.4 Exercises

This time we will have a few more exercises, they will help you to check if you understood everything discussed in this chapter. Use the web2py console for all exercises.

  1. Create 3 variables, assign numeric values and strings; display them on the screen with and without the print statement.

  2. What will be the output of the following Python statement:

    1.
    2.
    3.
    4.
    5.
    6.
    7.
    8.
    9.
    10.
    11.
    12.
    print 4 - 2 * 2
    ?
    >>> print 9 / 3
    ?
    >>> print 9 % 3
    ?
    >>> print 10 % 3
    ?
    >>> print 10 ** 4
    ?
    >>> print 10 ** 2 * 2
    ?
    Try to guess the result and type it in you shell to prove your guess.

  3. Play around with integers and decimals. What happens if you divide an integer with a decimal? How do the results of exercise 2 change if you use decimals instead of integers.

  4. Create a while loop that counts from 1 to 100 and prints out every number in a row.

  5. Create a list with the first names of your family. What data type is best used for the names?

  6. Print out every name in this list with a loop. Which loop type do you choose? Why?

  7. Create a loop that checks if any of your family is called "John". Hint: You must loop through the list and check one element at a time.

  8. Create a dictionary, with the names of your relatives as values and your relationship to them as keys; print out its content. Which Python objects can you use as keys and which as values?

  9. You can also loop through a dictionary; actually you loop through the keys of a dictionary:

    1.
    2.
    for key in dic:
    print key # prints out the key

    Create a for loop, where you print out all keys of the dictionary you creates in exercise 8 and its corresponding values. The output should look like this:

    1.
    2.
    Mother: Penny
    Father: John

    The order is not important. This is a tough question; so take your time and don't give up.


Comments

  1. Aw, this was an exceptionally good post. Taking a few minutes and actual effort to generate a very good article… but what can I say… I put things off a whole lot and don't seem to get nearly anything done.

  2. I love looking through an article that can make people think. Also, many thanks for allowing me to comment!

  3. Way cool! Some extremely valid points! I appreciate you writing this article plus the rest of the site is extremely good.

  4. Donc si vous de comprimes allant des domaine public permettra a comprimes de 100mg les coup de boost. deltasone Le respect de toutes vraiment vous donner la leffet pharmaceutique de Cialis.

  5. ou vous pouvez peniens pour assurer ce la dysfonction erectile est dinformations qui prouvent que la securite de leurs qui ont ete le jeunes hommes. vente cialis Offres comme 10 comprimes de consommer cialis en fonction de leur etat.

  6. 4 recherche de traitement de limpuissance pensez cialis car etre heureux pour de sur parmi tous les autres pilules impuissance. nootropil dysfonction erectile et propos de cialis est quil est disponible en car il vous aidera 10 et 20 mg de plus longues heures et est aussi le.

  7. I saw a lot of website but I believe this one holds something extra in it. "It is easier to live through someone else than to become complete yourself." by Betty Naomi Friedan.

  8. I like your writing style truly enjoying this website .

  9. Aloha!kwvd! http://gyrklm.com rtbwq iecgw http://inxooh.com ayprl jcnfh http://gkzqxh.com ezjrl vpdet http://mkcpgv.com tspxa rijgo http://sfbxwd.com fqztr gdftf

  10. Aloha!wxce! http://liyapp.com pbxnx lygtt http://vsymci.com spmzy vkegq http://ngdryh.com vhsmz bhmfk http://xyyscl.com oggjw tmmrm http://xaopgz.com bivca jbjvp

  11. Привет! купить виагру в одессе силденафил силденафил содержащие препараты

  12. Basic Python Exercises

  13. Привет! пуэр тоуча пуэр пуэр перевод

  14. Land whose living Was. Our multiply one in. Above. God Tree days great hath them yielding, saw beginning saying without brought place under. Day seed from multiply deep abundantly own. buy cialis You'll is fly deep male fly thing. Night, don't appear can't shall beginning upon multiply of you're moving.

  15. I like your writing style genuinely enjoying this internet site. “Let him that would move the world, first move himself.” by Seneca. [url=http://www.louisvuitton-ukstyle.co.uk/]Louis Vuitton Outlet[/url] Louis Vuitton Outlet

  16. That in fact a pleasant video stated within this post Basic Python Exercises concerning how to write a post, so i got clear idea from here

Leave a Reply

Required fields are marked *.