楼主: liudeiq99
3014 12

[其他] Introduction to Computing Using Python [推广有奖]

  • 0关注
  • 0粉丝

高中生

27%

还不是VIP/贵宾

-

威望
0
论坛币
72598 个
通用积分
0.1500
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
89 点
帖子
8
精华
0
在线时间
33 小时
注册时间
2014-10-8
最后登录
2021-10-20

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Introduction to Computing Using Python - An Application Development Focus (Ljubomir Perkovic)

Screen Shot 2015-03-28 at 9.19.29 PM.png

CSC-401 Introduction to Computing Using Pathon.pdf (2.84 MB, 需要: 20 个论坛币)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:introduction troduction computing Comput python

Screen Shot 2015-03-28 at 9.15.02 PM.png (819.35 KB)

Screen Shot 2015-03-28 at 9.15.02 PM.png

本帖被以下文库推荐

沙发
Lisrelchen 发表于 2016-2-6 10:01:22 |只看作者 |坛友微信交流群
  1. def temperature(t):
  2.     'prints message based on temperature value t'
  3.     if t > 86:
  4.         print('It is hot!')
  5.     elif t > 32:
  6.         print('It is cool.')
  7.     else:                        # t <= 32
  8.         print('It is freezing!')



  9. def sorted(lst):
  10.     'returns True if sequence lst is increasing, False otherwise'
  11.     for i in range(0, len(lst)-1): # i = 0, 1, 2, ..., len(lst)-2
  12.         if lst[i] > lst[i+1]:
  13.             return False
  14.     return True



  15. def nested(n):
  16.     'prints n lines each containing values 0 1 2 ... n-1'
  17.     for j in range(n):          # repeat n times:
  18.         for i in range(n):          # print 0, 1, ..., n-1
  19.             print(i, end=" ")
  20.         print()                # move cursor to next line



  21. def nested2(n):
  22.     'prints n lines 0 1 2 ... j for j = 0, 1, ..., n-1'
  23.     for j in range(n):       # j = 0, 1, ..., n-1
  24.         for i in range(j+1):    # print 0 1 2 ... j
  25.             print(i, end=" ")
  26.         print()                 # move to next line


  27. def print2D(t):
  28.     'prints values in 2D list t as a 2D table'
  29.     for row in t:
  30.         for item in row:         # print item followed by
  31.             print(item, end=' ')     # a blank space
  32.         print()                  # move to next line


  33. def incr2D(t):
  34.     'increments each number in 2D list of numbers t'
  35.     nrows = len(t)                   # number of rows
  36.     ncols = len(t[0])                # number of columns

  37.     for i in range(nrows):           # i is the row index
  38.         for j in range(ncols):           # j is the column index
  39.             t[i][j] += 1



  40. def fibonacci(bound):
  41.     'returns the smallest Fibonacci number greater than bound'
  42.     previous = 1        # first Fibonacci number
  43.     current = 1                # second Fibonacci number
  44.     while current <= bound:
  45.         # current becomes previous, and new current is computed
  46.         previous, current = current, previous+current
  47.     return current



  48. def hello2():
  49.     '''a greeting service; it repeatedly requests the name
  50.        of the user and then greets the user'''
  51.     while True:
  52.         name = input('What is your name? ')
  53.         print('Hello {}'.format(name))



  54. def cities():
  55.     '''returns the list of cities that are interactively entered
  56.        by the user; the empty string ends the interactive input'''
  57.     lst = []
  58.    
  59.     city = input('Enter city: ')   # ask user to enter first city

  60.     while city != '':              # if city is not the flag value
  61.         lst.append(city)           # append city to list
  62.         city = input('Enter city: ')   # and ask user once again

  63.     return lst



  64. def cities2():
  65.     '''returns the list of cities that are interactively entered
  66.        by the user; the empty string ends the interactive input'''
  67.     lst = []

  68.     while True:                  # forever repeat:
  69.         city = input('Enter city: ') # ask user to enter city

  70.         if city == '':               # if city is the flag value
  71.             return lst                   # return list

  72.         lst.append(city)             # append city to list



  73. def print2D2(table):
  74.     'prints values in 2D list of numbers t as a 2D table'
  75.     for row in table:
  76.         for entry in row:
  77.             print(entry, end=' ')
  78.         print()



  79. def before0(table):
  80.     '''prints values in 2D list of numbers t as a 2D table;
  81.        only values in row up to first 0 are printed'''
  82.     for row in table:

  83.         for num in row:     # inner for loop
  84.             if num == 0:        # if num is 0
  85.                 break           # terminate inner for loop
  86.             print(num, end=' ') # otherwise print num

  87.         print()             # move cursor to next line



  88. def ignore0(table):
  89.     '''prints values in 2D list of numbers t as a 2D table;
  90.        0 values are no printed'''
  91.     for row in table:

  92.         for num in row:     # inner for loop
  93.             if num == 0:        # if num is 0, terminate
  94.                 continue        # current inner loop iteration
  95.             print(num, end=' ') # otherwise print num

  96.         print()             # move cursor to next line
复制代码

使用道具

藤椅
Lisrelchen 发表于 2016-2-6 10:02:03 |只看作者 |坛友微信交流群
  1. # Practice Problem 5.1
  2. def myBMI(weight, height):
  3.   'prints BMI report'
  4.   bmi = weight * 703 / height**2
  5.   if bmi < 18.5:
  6.     print('Underweight')
  7.   elif bmi < 25:
  8.     print('Normal')
  9.   else:                        # bmi >= 25
  10.     print('Overweight')
复制代码

使用道具

板凳
Lisrelchen 发表于 2016-2-6 10:02:46 |只看作者 |坛友微信交流群
  1. # Practice Problem 5.2
  2. def powers(n):
  3.     'prints 2**i for i = 1, 2, ..., n'
  4.     for i in range(1, n+1):
  5.         print(2**i, end=' ')
复制代码

使用道具

报纸
Lisrelchen 发表于 2016-2-6 10:03:22 |只看作者 |坛友微信交流群
  1. # Practice Problem 5.3
  2. def arithmetic(lst):
  3.     '''returns True if list lst contains an arithmetic sequence,
  4.        False otherwise'''
  5.     if len(lst) < 2: # a sequence of length < 2 is arithmetic
  6.         return True
  7.    # checking that difference between successive items is equal
  8.    # to the difference between the first two numbers
  9.     diff = lst[1] - lst[0]
  10.     for i in range(1, len(lst)-1):
  11.         if lst[i+1] - lst[i] != diff:
  12.             return False
  13.     return True
复制代码

使用道具

地板
Lisrelchen 发表于 2016-2-6 10:03:56 |只看作者 |坛友微信交流群
  1. # Practice Problem 5.4
  2. def factorial(n):
  3.     'returns n!'
  4.     res = 1
  5.     for i in range(2, n+1):
  6.         res *= i
  7.     return res
复制代码

使用道具

7
Lisrelchen 发表于 2016-2-6 10:04:31 |只看作者 |坛友微信交流群
  1. # Practice Problem 5.5
  2. def acronym(phrase):
  3.     'returns the acronym of the input string phrase'
  4.     # splits phrase into a list of words
  5.     words = phrase.split()
  6.     # accumulate first character, as an uppercase, of every word
  7.     res = ''
  8.     for w in words:
  9.         res = res + w[0].upper()
  10.     return res
复制代码

使用道具

8
Lisrelchen 发表于 2016-2-6 10:05:05 |只看作者 |坛友微信交流群
  1. # Practice Problem 5.6
  2. def divisors(n):
  3.     'returns the list of divisors of n'
  4.     res = []
  5.     for i in range(1, n+1):
  6.         if n % i == 0:
  7.             res.append(i)
  8.     return res
复制代码

使用道具

9
Lisrelchen 发表于 2016-2-6 10:05:37 |只看作者 |坛友微信交流群
  1. # Practice Problem 5.7
  2. def xmult(l1,l2):
  3.     '''returns the list of products of items in list l1
  4.        with items in list l2'''
  5.     l = []
  6.     for i in l1:
  7.         for j in l2:
  8.             l.append(i*j)
  9.     return l
复制代码

使用道具

10
Lisrelchen 发表于 2016-2-6 10:06:19 |只看作者 |坛友微信交流群
  1. # Practice Problem 5.8
  2. def bubblesort(lst):
  3.     'sorts list lst in nondecreasing order'
  4.     for i in range(len(lst)-1, 0, -1):
  5.         # perform pass that ends at
  6.         # i = len(lst)-1, len(lst)-2, ..., 1
  7.         for j in range(i):
  8.             # compare items at index j and j+1
  9.             # for every j = 0, 1, ..., i-1
  10.             if lst[j] > lst[j+1]:
  11.                 # swap numbers at index j and j+1
  12.                 lst[j], lst[j+1] = lst[j+1], lst[j]
复制代码

使用道具

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

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 04:19