Python
  Home arrow Python arrow Page 2 - Python Conditionals, Lists, Dictionaries, and Operators
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Forums Sitemap 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

Python Conditionals, Lists, Dictionaries, and Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2007-11-26


    Table of Contents:
  • Python Conditionals, Lists, Dictionaries, and Operators
  • Elif
  • Lists
  • Tuples
  • Dictionaries
  • Operators

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Python Conditionals, Lists, Dictionaries, and Operators - Elif
    (Page 2 of 6 )

    The Elif works like the Else If in other languages. It states that if the original If statement is False, and then the Elif part is true, to do this. Here it is in code:


    #!/usr/local/bin/python


    beers = 100



    while beers != 0:

    beers = input (“How many beers are on the wall?”)

     

        if beers >= 1 and beer <= 20:

            print “Almost there. Take one down and pass it around!”

     

        elif beers >=21 :

            print “You got a lot of drinking to do!”


    print “You should seek help!”

    This program starts off creating a variable named beers. It then assigns the value 100 to it. Next, it creates a loop, that will continue looping while the value of beers is not equal to 0. Next it goes into an If statement that asks the user how many beers on are the wall. It then takes whatever numeric value the user enters and stores it in the beers variable. If the value is 0, it will exit the loop and print “You should seek help!” If the value is between 1 and 20 (greater than or equal to one AND less than or Equal to 20), it will print: “Almost there. Take one down and pass it around!” and continue through the loop. If the user enters a value equal to or greater than 21, it will print “You got a lot of drinking to do!” and once more continue through the loop.



     
     
    >>> More Python Articles          >>> More By James Payne
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted



     



    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 11 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek