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()
  • 相关阅读:
    Linux内核的异常修复原理
    sudo: insmod: command not found
    在Qemu+ARM上运行Minix3内核
    2021.34 面对干扰
    2021.33 实践
    selenium+python自动化106
    python测试开发django-111.模型管理器(models.Manager)
    python笔记64
    python笔记63
    python笔记62
  • 原文地址:https://www.cnblogs.com/zichuan/p/9695070.html
Copyright © 2011-2022 走看看