Home arrow Python arrow Page 2 - Python Conditionals, Lists, Dictionaries, and Operators

Elif - Python

In our last article we learned how to get input from the user, store data in a variable, and work with some basic operators to manipulate that data. In this article we will learn to use Conditional Statements and possibly create functions. So wipe that mustard off your chin, clean the dishes, and let's get to work.

TABLE OF CONTENTS:
  1. Python Conditionals, Lists, Dictionaries, and Operators
  2. Elif
  3. Lists
  4. Tuples
  5. Dictionaries
  6. Operators
By: James Payne
Rating: starstarstarstarstar / 5
November 26, 2007

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- 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

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: