Skip to content

Commit 83f2277

Browse files
committed
add chapter01 and 06
1 parent ded6d81 commit 83f2277

7 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# coding:utf-8
2+
3+
print("Hello, World")

python3code/chapter01/nameage.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# coding:utf-8
2+
'''
3+
filename: nameage.py
4+
'''
5+
6+
name = input("What is your name?")
7+
age = input("How old are you?")
8+
9+
print("Your name is: ", name)
10+
print("You are " + age + " years old.")
11+
12+
after_ten = int(age) + 10
13+
print("You will be " + str(after_ten) + " years old after ten years.")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#coding:utf-8
2+
3+
"""
4+
请计算:19+2*4-8/2
5+
"""
6+
7+
a = 19 + 2 * 4 - 8 / 2
8+
print(a)
857 Bytes
Binary file not shown.

python3code/chapter06/exit_file.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# coding:utf-8
2+
'''
3+
filename:exit_file.py
4+
'''
5+
6+
import sys
7+
8+
for i in range(10):
9+
if i == 5:
10+
sys.exit()
11+
else:
12+
print(i)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#coding:utf-8
2+
'''
3+
filename: moduleexample.py
4+
'''
5+
6+
class Book:
7+
lang = "python"
8+
9+
def __init__(self, author):
10+
self.author = author
11+
12+
def get_name(self):
13+
return self.author
14+
15+
def foo(x):
16+
return x * 2
17+
18+
#python = Book("laoqi")
19+
#python_name = python.get_name()
20+
21+
#mul_result = foo(2)
22+
23+
if __name__ == "__main__": #⑤
24+
python = Book("laoqi")
25+
python_name = python.get_name()
26+
print(python_name)
27+
28+
mul_result = foo(2)
29+
print(mul_result)

python3code/chapter06/sys_file.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# coding:utf-8
2+
'''
3+
filename: sys_file.py
4+
'''
5+
6+
import sys
7+
8+
print("The file name: ", sys.argv[0])
9+
print("The number of argument", len(sys.argv))
10+
print("The argument is: ", str(sys.argv))

0 commit comments

Comments
 (0)