python assignment & homework help

Post on 16-Jan-2016

22 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Python is Widely used Programming Language nowdays and the University and High School Assignments and Homework are the Part of the Curriculum. So with the help of Online Tutoring Service of myassignmenthelp you can achieve your Goals at the Right Time

TRANSCRIPT

www.myassignmenthelp.net

PYTHON PROGRAMMING

LANGUAGE

• Python is a general-purpose interpreted, interactive, object-oriented and high-level programming language. Python was created by Guido van Rossum in the late eighties and early nineties. Like Perl, Python source code is also now available under the GNU General Public License (GPL).

INTRODUCTION

• First download Python-2.4.1.exe by following this link. If you are a dialup user, keep in mind that the file is around 10MB

• Run the file you just downloaded, and follow the prompts.

• OK! Hopefully now everything is good! Now, to test if that just worked, type this in your DOS window:

python –V

INSTALLING PYTHON

Multiplication

>>>5*2

10

>>>3**2

9

Division

>>>21/7

3

Addition

>>>1+1

2

>>>20+80

100

Subtraction

>>>6-4

2

MATH IN PYTHON

• #Variables

Variables store a value, that can be looked at or changed at a later time.

#Variable demonstrated

print “this program is demo of variables”

Print “ the value of v is now ”, v

V=v+1

• Writing program in python to a file is very easy. Python programs are simply text documents. You can open them up in notepad.

#A simple program

print “Mary has a little lamb”

PROGRAM IN A FILE, AND VARIABLES

• The “while” loop

a=0

While a<10:

a=a+1

Print a

LOOPS

• Basically, the for loop does something foe every value in a list. The way it is set out is a little confusing, but otherwise is very basic.

• #cheerleading program

Word = raw_input(“ who do you go for? ”)

For letter in word:

Call = “Gimme a “ + letter + “!”

Print call

Print letter + “!”

Print “what does that spell?”

Print word + “!”

FOR LOOP

• If {conditions to b e met}:

{do this}

{and this}

[but this happens regardless}

{because it is not indented}

Example1:

Y = 1

If y = = 1

Print ‘y still equals 1, I was just checking”

CONDITIONAL STATEMENTS

• Python has lot of pre-made functions, that you can use right now, simply by ‘calling’ them. ‘Calling’ is a function involves you giving a function input, and it will return a value as output.

• Here is a general form that calling a function takes.

function_name(parameters)

FUNCTIONS

• To open a text file you use, well, the open() function. Seems sensible. You pass certain parameters to open() to tell it in which way the file should be opened –’r’ for read only and –’w’ for writing only, -’a’ for appending and ‘r’+ both reading and writing.

• Ex-

openfile = open(‘pathtofile’, ‘r’)

Openfile.read()

FILE I/O

ANY QUERY

WWW.MYASSIGNMENTHELP.NET

top related