zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    APUE.3源码编译(Ubuntu16.04)
    《UNIX环境高级编程》(第三版)阅读笔记---2018-5-9
    css回归之用户界面
    css回归之文本
    js回归之字符串
    js回归之BOM
    js回归之事件
    百度前端面试总结
    书单
    剑指offer做题收获之一:补码
  • 原文地址:https://www.cnblogs.com/zichuan/p/9695070.html
Copyright © 2011-2022 走看看