Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
33 views

Python Practice

This document provides an introduction to Python programming. It covers starting Python in the interactive shell or IDLE, using basic statements and numeric operators to write simple programs, and defining functions to group related statements. Examples show how to print output, perform calculations, save and run Python files. The document concludes with practice problems, such as writing code to compute the distance between two points and calling a defined function.

Uploaded by

m.farid munanda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Python Practice

This document provides an introduction to Python programming. It covers starting Python in the interactive shell or IDLE, using basic statements and numeric operators to write simple programs, and defining functions to group related statements. Examples show how to print output, perform calculations, save and run Python files. The document concludes with practice problems, such as writing code to compute the distance between two points and calling a defined function.

Uploaded by

m.farid munanda
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to

Python -
Practice
Overview

• Starting Python
• Simple programming
• Numeric operators
• Simple program with function
Starting Python

• When you start Python, you will see


something like:
Python 3.5.1 (v3.5.1:37a07cee5969,
Dec 6 2015, 01:54:25) [MSC v.1900
64 bit (AMD64)] on win32
Type "copyright", "credits" or
"license()" for more information.
>>>
Starting Python
• The “>>>” is a Python prompt indicating that
Python is ready for us to give it a command.
These commands are called statements.
>>> print("Hello, world")
Hello, world
>>> print(2+3)
5
>>> print("2+3=", 2+3)
2+3= 5
>>>
Using IDLE Python

• Open IDLE Python


• Open new file
• Write the code
• Save the code as filename.py
• Run module
Simple program 1
Simple program 2
Simple program 3
Simple program 3
Numeric operators
Numeric operators
Simple program 4
Practice
Practice

• Write the Python code to compute the distance


between two points.
Simple program with function
• Usually we want to execute several
statements together that solve a common
problem. One way to do this is to use a
function.
>>> def hello():
print("Hello")
print("Computers are Fun")

>>>
Simple program with function
>>> def hello():
print("Hello")
print("Computers are Fun")
>>>

A function is invoked (or called) by typing its


name.
>>> hello()
Hello
Computers are Fun
>>>

You might also like