Array

Creating Your First Application

Must Read

Second Mortgage Home Equity Loan

Your home is an investment. And like any investment, it is worth money. More specifically, your home has equity....

Florida Mortgage Lenders Offer Home Improvement Loans and Lines of Credit – What Are They?

Home equity loans and home equity lines of credit are differing ways to use the equity in your home...

Geolocation Classes

The flash.events.GeolocationEvent class is a new Event object that contains updated geolocation information. The new flash.sensors.Geolocation class is a...
Admin
test

After all this time, you might have started wondering whether you would get to write any code at all in this chapter. The first application won’t be very fancy, but it’ll be more than a simple Hello World kind of application. You can use any editor that outputs pure text in this section. Notepad will work just fine. Listing 1-1 shows the code you should type in your editor.

A simple first application that multiplies two numbers

def mult(a, b):
return a * b
print(‘5 * 10 =’),
print(mult(5, 10))

Just five lines, including the blank line between the function and the main code, are all you need for this example. Functions begin with the def keyword. You then give the function a name, mult in this case, followed by a list of arguments (if any) — a and b for this example.

The content of the function is indented with a tab. In this case, the function simply returns the value of multiplying a by b. Except for the indentation requirement, this could easily be a function written in any other language.

The main code section comes next. In this case, the code begins by printing 5 * 10 =. Notice that you enclose the string values in single quotes. The function call ends with an odd-looking comma. This comma tells the interpreter not to add a /n (newline) character after the print() call.

At this point, the code calls print() a second time, but it calls mult() instead of writing text directly. The output of mult() is an integer, which IronPython automatically converts to a string for you and then prints out. You’ll find that IronPython does a lot of work for you in the background — dynamically.

Save the code you’ve typed into Notepad as MyFirst.py. Make sure you choose All Files in the Save As Type field so that Notepad doesn’t add a .txt extension to the output. To execute this example, type IPY MyFirst.py at the command line and press Enter. Figure 1-10 shows the output from this quick example.

The output of the example is a simple equation.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest News

Top 10 Provinces of Thailand Not to be missed for Travel

10 SuratthaniThe source of the proverbial Chaiya salted egg. Surat Thani is a province with many attractions,...

Underlight As Accent, For Power and The Main Light for Photography

Underlighting, in which fill or accent light comes from under the topic, is not widely used technique in the traditional Portraits, even though it will have...

How To Fix Overexposure As A Creative Tool, The Complete Guide

As an creative tool, overexposure is sort of underrated. What I’m close to propose could be a deliberate and well thought out technique for...

7D Mark II is Canon’s best DSLR cameras without full-frame sensor.

The expected long-awaited Canon EOS 7D Mark II are shipping in November for $ 1,799 without a lens. With a higher price tag, you...

Low key photography and How to isolate your subject.

Low key photography doesn’t depend on underexposure to make its point; the key to low key is that the majority of tones, even correctly...

More Articles Like This