Python
  Home arrow Python arrow Page 2 - Python Conditionals, Lists, Dictionari...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
eWeek
 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? 
PYTHON

Python Conditionals, Lists, Dictionaries, and Operators
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · In [7]: suess = ['I', 'like', 'green', 'eggs', 'and', 'spam']In [8]: print...
       · I used a combo box in form along with text boxes.. now when the user submit the...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway