计算原理课程笔记(一)

来源:互联网 发布:js给div设置 编辑:程序博客网 时间:2024/05/21 06:34

计算原理课程笔记(一)

这里写图片描述

<python>"""This is a docstring for the module:This module demonstrates the use of docstrings."""def repeat_string(string, num):    """    This is a docstring for a function:    Return a new string that repeats the input    string num times.    """    newstring = ""    for dummy_loop_counter in range(num):        newstring += string    return newstringclass SimpleCounter:    """    This is a docstring for a class:    Simple counter class that can only increment.    """    def __init__(self, initial_val = 0):        self._val = initial_val    def increment(self):        """        This is a docstring for a method:        Increment counter.        """        self._val += 1    def get_value(self):        """        This is a docstring for another method:        Return current value of the counter.        """        return self._val<python>

这里写图片描述
这里写图片描述
这里写图片描述

<python>import poc_helper_stuff as providedimport poc_mancala_testsuitepoc_mancala_testsuite.run_suite(SolitaireMancala)import poc_mancala_guipoc_mancala_gui.run_gui(SolitaireMancala())<python>

导入poc_helper_stuff 模块
导入测试模块
导入gui模块

<python>def __init__(self, initial_balance):    """Creates an account with the given balance."""    self.banlance=initial_balance    self.fees=0<python>

self.banlance表示实例的变量

<python>lst+=[lst[-3]+lst[-2]+lst[-1]]<python>

[]转化lst[-3]+lst[-2]+lst[-1]为列表

0 0