再重新捡起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()

相关文章:

  • 2021-11-23
  • 2021-08-22
  • 2021-12-13
  • 2021-07-30
  • 2022-12-23
  • 2021-07-16
  • 2021-12-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-20
  • 2021-08-09
  • 2021-09-08
  • 2018-04-18
  • 2018-11-24
相关资源
相似解决方案