Python学习笔记系列——九九乘法表&猜大小

  再重新捡起Python,数据库短时间之内已经没啥看的了,不知道今年结束之前能不能Python入门,一直认为自己是没有编程思想的。。。

1、九九乘法表

#九九乘法表实现的一种方式之一
def Multiplication_table():
    for i in range(1,10):
        for j in range(1,i+1):
            print("{0}*{1}={2}" .format (j,i,j*i),end=" ")
        print(" ")
Multiplication_table()

 

2、小游戏:猜大小

import random
#先投掷骰子
def roll_dice(numbers=3,points=None):
    print('<<<<< ROLE THE DICE! >>>>>')
    if points is None:
        points = []
    while numbers>0:
        point = random.randrange(1,7)
        points.append(point)
        numbers = numbers - 1
    return points

#大与小的定义
def roll_result(total):
    if 11 <= total <=18:
        return 'Big'
    elif 3 <= total <=10:
        return 'Small'

def start_time():
    print('<<<<< GAME STARTS! >>>>>')
    choices = ['Big','Small']   #规定正确的输入
    yours_choices = input('Big or Small:')
    if yours_choices in choices:  #将不符合输入规范的数据过滤掉
        points = roll_dice()
        total = sum(points)
        if yours_choices == roll_result(total):
            print('The points are',points,'You Win!')
        else:
            print('The points are',points,'You Lose!')
    else:
        print('Invalid Words')
        start_time()
start_time()
posted @ 2018-09-24 11:22  zzz紫川  阅读(346)  评论(0编辑  收藏  举报