10 月 212020
 
# -*- coding:utf-8 -*-
def number_test():  # 定义函数,测试号码所属运营商
    while True:  # 循环提示用户输入号码,在输入长度不匹配或输入号码匹配运营商号段列表时终止循环
        number = input('Enter your number: ')  # 用户输入赋值变量
        china_mobile = [134, 135, 136, 137, 138, 139, 150, 151, 152,
                        157, 158, 159, 182, 183, 184, 187, 188, 147, 178, 1705]
        china_unicom = [130, 131, 132, 155, 156, 185, 186, 145, 176, 1709]
        china_telecom = [133, 153, 180, 181, 189, 177, 1700]
        first_three = int(number[0:3])  # 取用户输入字符串第1-3位转换整数类型并赋值变量
        first_four = int(number[0:4])  # 取用户输入字符串第1-4位转换整数类型并赋值变量

        if len(number) == 11:  # 判断用户输入长度是否为11位

            if first_three in china_mobile or first_four in china_mobile:  # 判断用户输入前三位或前四位是否在移动号段列表中
                print('Operator: China Mobile')
                print('We\'re sending verification code via text to your phone: ', number)
                break  # 匹配则终止判断
            elif first_three in china_telecom or first_four in china_telecom:  # 如果不在移动号段列表,继续判断用户输入前三位是否在电信号段列表中
                print('Operator: China Telecom')
                print('We\'re sending verification code via text to your phone: ', number)
                break  # 匹配则终止判断
            elif first_three in china_unicom or first_four in china_unicom:  # 如果不在移动号段和电信号段列表,继续判断用户输入前三位是否在联通号段列表中
                print('Operator: China Unicom')
                print('We\'re sending verification code via text to your phone: ', number)
                break  # 匹配则终止判断
            else:  # 用户输入不存在于号段列表中则提示没有此运营商
                print('No such a operator')

        else:  # 反之,则提示用户输入长度不足
            print('Invalid length, your number should be in 11 digits')


# 调用函数
number_test()
10 月 212020
 
# -*- coding:utf-8 -*-
import random  # 导入内置模块,用以产生随机数【pycharm:行内注释,#号前需空两个字符,#号后需空一个字符】


# 定义摇色子函数,次数参数默认为3,点数参数默认为空
def roll_dice(numbers=3, points=None):  # 【PEP 8: E251 unexpected spaces around keyword / parameter equals】
    print('>>>>> ROLL THE DICE! <<<<<')
    if points is None:  # 判断,如果点数参数值为空,将空列表赋值给该变量
        points = []
    while numbers > 0:  # while循环,直到次数值不在大于0时终止,初始值为3,每循环一次减1
        point = random.randrange(1, 7)  # 在1-6范围内取随机数赋值给点数
        points.append(point)  # 将点数追加写入列表
        numbers = numbers - 1  # 最多循环3次,成功获取3个随机数,跳出循环
    return points  # 返回生成的3个随机数


def roll_result(total):  # 定义比较大小函数
    big = 11 <= total <= 17  # 比较运算的布尔值True赋值给变量【pycharm:变量应当是小写】
    small = 4 <= total <= 10  # 比较运算的布尔值True赋值给变量
    if big:  # 判断,如果big == True 则返回提示Big
        return 'Big'
    elif small:  # 继续判断,如果small == True 则返回Small提示
        return 'Small'


def start_game():  # 定义启动游戏函数
    your_money = 1000  # 初始持有金额并赋值变量【PEP 8: E225 missing whitespace around operator】
    while your_money > 0:  # 循环,游戏重复开始,直到持有金额不再大于0时终止
        print('>>>>> GAME STARTS! <<<<<')
        choices = ['Big', 'Small']  # 定义用户有效输入值列表并赋值变量
        your_choice = input('Big or Small: ')  # 提示用户输入并赋值变量

        if your_choice in choices:  # 执行判断,是否用户输入值,存在于列表中,匹配则继续执行
            your_bet = int(input('How much you wanna bet? '))  # 用户输入下注金额赋值变量
            points = roll_dice()  # 调用函数生成随机数
            total = sum(points)  # 调用函数计算随机数累加值并赋值变量
            win = your_choice == roll_result(total)  # 调用roll_result(total)函数取得实际大小值,与用户输入值布尔运算,取得布尔值赋值变量
            if win:  # 判断,win == True则执行
                print('The points is ', points, ' You Win')  # 打印点数
                print('You gained {}, you have {} now'.format(your_bet, your_money + your_bet))  # 打印下注值和当前持有值
                your_money = your_money + your_bet  # 更新当前持有值
            else:  # 判断,反之,youWin == False则执行
                print('The points is ', points, ' You Lose')
                print('You lose {}, you have {} now'.format(your_bet, your_money - your_bet))
                your_money = your_money - your_bet
        else:  # 反之,提示输入无效字符
            print('Invalid Words')
    else:  # 反之,持有金额小于等于0时,提示游戏结束,退出执行
        print('GAME OVER')


start_game()  # 调用函数启动游戏【PEP 8: E305 expected 2 blank lines after class or function definition, found 1】
10 月 212020
 
# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
10 月 212020
 
PS D:\Python\mysite> django-admin.exe

Type 'django-admin help <subcommand>' for help on a specific subcommand.

Available subcommands:

[django]
check
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
makemigrations
migrate
runserver
sendtestemail
shell
showmigrations
sqlflush
sqlmigrate
sqlsequencereset
squashmigrations
startapp
startproject
test
testserver
Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.). 
PS D:\Python\mysite>