计算原理课程笔记(一)

计算原理课程笔记(一)

这里写图片描述

<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 newstring

class 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 provided
import poc_mancala_testsuite
poc_mancala_testsuite.run_suite(SolitaireMancala)
import poc_mancala_gui
poc_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]为列表

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值