coursera_intro_to_python_notebook_1
2013-04-25 11:24
525 查看
http://www.codeskulptor.org/#user10_RPMkJnEXC4v3qe8.py
this is my first mini python project
1 function&&more operations
function starts with key word "def",such as an example
def compute_area(base,height):
area= ( 1 /2 ) * base * height;
return area
the end of the header is a colon,means the following lines indented belongs to the function,no matther how many lines, but with the same amount
so,the block indented with a same amount belongs to the function
in last case , it has 2 lines(with the same amount indented).
when you stop the indentation , the block of code is done
Call the function
a1 = compute_area(3,8)
print a1
#print 12
def print_hello():
print "hello world"
Call the function
print_hello()
#OK
a=print_hello()
print a;
#will print "None"
if you forget or you dont need a return statement,it automatically add one
__________________________________________________________________________________________
more operations
a="0"
b="1"
print a,b,":00"
#show "0 1 :00"
+operator
combine the strings
print a+b+":00"
#show "01:00"
function str: convert something to string
such as
hour=3
print str(hour)
import module:
such as
improt math
improt simplegui
print math.pi
improt random
this is my first mini python project
1 function&&more operations
function starts with key word "def",such as an example
def compute_area(base,height):
area= ( 1 /2 ) * base * height;
return area
the end of the header is a colon,means the following lines indented belongs to the function,no matther how many lines, but with the same amount
so,the block indented with a same amount belongs to the function
in last case , it has 2 lines(with the same amount indented).
when you stop the indentation , the block of code is done
Call the function
a1 = compute_area(3,8)
print a1
#print 12
def print_hello():
print "hello world"
Call the function
print_hello()
#OK
a=print_hello()
print a;
#will print "None"
if you forget or you dont need a return statement,it automatically add one
__________________________________________________________________________________________
more operations
a="0"
b="1"
print a,b,":00"
#show "0 1 :00"
+operator
combine the strings
print a+b+":00"
#show "01:00"
function str: convert something to string
such as
hour=3
print str(hour)
import module:
such as
improt math
improt simplegui
print math.pi
improt random
相关文章推荐
- Coursera Using python to access Web data quiz 4
- Python 101 – Intro to XML Parsing with ElementTree
- Coursera-An Introduction to Interactive Programming in Python (Part 1)-Mini-project— Rock-paper-scissors-lizard-Spock
- Coursera-An Introduction to Interactive Programming in Python (Part 1)-Mini-project #3 —"Stopwatch: The Game"
- [Coursera][Rice] An introduction to interactive Programming in Python Week 1
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 6 Blackjack
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 7 Spaceship
- Coursera-An Introduction to Interactive Programming in Python (Part 1)-Mini-project — “Guess the number” game
- Coursera_An Introduction to Interactive Programming in Python_Music Player
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 8 RiceRock
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 4 Pong
- [Coursera][Rice] An introduction to interactive Programming in Python Week 2 3
- Coursera-An Introduction to Interactive Programming in Python (Part 1)-Mini-project #4 —"Pong"
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 1 Rock-paper-scissors
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 5 Memory
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 2 Guess the number
- Python pandas 0.19.1 Intro to Data Structures 数据结构介绍 文档翻译
- 【coursera 学习笔记】An Introduction to Interactive Programming in Python--week1
- Coursera Using python to access Web data
- Coursera Using python to access Web data quiz 5