楼主: Nicolle
1931 337

Project Python:Interactive Book Teaching Code in Python   [推广有奖]

版主

巨擘

0%

还不是VIP/贵宾

-

TA的文库  其他...

Python Programming

SAS Programming

Structural Equation Modeling

威望
16
论坛币
12314633 个
学术水平
2816 点
热心指数
2797 点
信用等级
2624 点
经验
429649 点
帖子
18433
精华
80
在线时间
6975 小时
注册时间
2005-4-23
最后登录
2018-10-18

Nicolle 学生认证  发表于 2018-10-8 07:11:21 |显示全部楼层
本帖最后由 Nicolle 于 2018-10-8 11:08 编辑

Project Python is a free interactive book that will teach you to code in Python, using graphics, animations, and games. You’ll also learn ways to solve classical computer science problems, principles of software design, and how to analyze algorithm performance. No prior experience required; you’ll write code to draw a smiley face by the end of the first chapter.

By Devin Balkcom, with significant contributions from Tom Cormen and Hany Farid. We recommend using an updated version of Chrome or Firefox to run the interactive examples.

Contents

已有 2 人评分经验 论坛币 热心指数 收起 理由
QWERTY1123 + 5 + 2 精彩帖子
zl89 + 80 精彩帖子

总评分: 经验 + 80  论坛币 + 5  热心指数 + 2   查看全部评分

本帖被以下文库推荐

stata SPSS
summers1985 发表于 2018-10-8 09:45:36 |显示全部楼层
Thanks for your kindly sharing.
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

回复

使用道具 举报

Nicolle 学生认证  发表于 2018-10-8 11:20:59 |显示全部楼层
  1. in_file = open("states.txt", "r")

  2. for line in in_file:
  3.     print( line )

  4. in_file.close()
复制代码
回复

使用道具 举报

Nicolle 学生认证  发表于 2018-10-8 11:21:24 |显示全部楼层
  1. # gettysburg.py
  2. # CS 1 demo by THC to write a file.
  3. # It writes the file gettysburg.txt into the project folder in the workspace.

  4. out_file = open("gettysburg.txt", "w")
  5. out_file.write("Four score and seven years ago,\n")
  6. out_file.write("our fathers brought forth on this continent, a new nation,\n")
  7. out_file.write("conceived in Liberty, and dedicated to the proposition ")
  8. out_file.write("that all men are created equal.\n")
  9. out_file.close()
复制代码
回复

使用道具 举报

Nicolle 学生认证  发表于 2018-10-8 11:22:58 |显示全部楼层
Nested loops
  1. import sys
  2. # print right-indented using 'length' characters,
  3. #  no newline
  4. def print_justified(value, length):
  5.     sys.stdout.write(str(value).rjust(length))

  6. row = 1
  7. while row < 10:     # the header for the outer loop
  8.     column = 1
  9.     while column < 10:   # the header for the inner loop
  10.         print_justified(row * column, 3)
  11.         column += 1

  12.     print()  # newline

  13.     row += 1
复制代码
回复

使用道具 举报

Nicolle 学生认证  发表于 2018-10-8 11:24:06 |显示全部楼层
Nested for-loops
  1. import sys
  2. def print_justified(value, length):
  3.     sys.stdout.write(str(value).rjust(length))

  4. for row in range(1, 10):
  5.     for column in range(1, 10):
  6.         print_justified(row * column, 3)

  7.     print()  # newline
复制代码
回复

使用道具 举报

Nicolle 学生认证  发表于 2018-10-8 11:25:10 |显示全部楼层
Selection sort
  1. def selection_sort(the_list):
  2.     n = len(the_list)     # makes it easy to denote the length of the list

  3.     for i in range(n - 1):
  4.         # Find the minimum value in the sublist starting at index i.
  5.         # smallest will hold the index of the smallest value we have found
  6.         # so far in the sublist.
  7.         smallest = i

  8.         for j in range(i, n):
  9.             if the_list[j] < the_list[smallest]:
  10.                 smallest = j

  11.         # After the inner loop, smallest has the index of the smallest
  12.         # value in the sublist starting at index i.  Swap the values
  13.         # at index i and smallest.
  14.         temp = the_list[i]
  15.         the_list[i] = the_list[smallest]
  16.         the_list[smallest] = temp

  17. grade_list = [89, 45, 85, 81, 77, 94, 22, 79, 92, 91]
  18. print( "grade_list before sorting: " + str(grade_list) )

  19. selection_sort(grade_list)
  20. print("grade_list after sorting:  " + str(grade_list) )
复制代码
回复

使用道具 举报

Nicolle 学生认证  发表于 2018-10-8 11:28:43 |显示全部楼层
Factoring Selection Sort
  1. def selection_sort(the_list):
  2.     n = len(the_list)     # makes it easy to denote the length of the list

  3.     for i in range(n - 1):
  4.         # Find the minimum value in the sublist starting at index i.

  5.         smallest = i
  6.         for j in range(i, n):
  7.             if the_list[j] < the_list[smallest]:
  8.                 smallest = j

  9.         # Swap the values at index i and smallest.
  10.         temp = the_list[i]
  11.         the_list[i] = the_list[smallest]
  12.         the_list[smallest] = temp

  13. grade_list = [89, 45, 85, 81, 77, 94, 22, 79, 92, 91]
  14. selection_sort(grade_list)
  15. print("grade_list after sorting:  " + str(grade_list) )
复制代码
回复

使用道具 举报

xujingjun 发表于 2018-10-8 12:28:48 |显示全部楼层
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

回复

使用道具 举报

ccmchy 在职认证  企业认证  发表于 2018-10-8 14:06:55 |显示全部楼层
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 我要注册

GMT+8, 2018-10-18 13:49