python(猜数字,做10以内的乘法题,打印九九成乘法表)

一:猜数字

猜数字游戏:
1.系统随机生成一个1~100的数字;
2.用户共有5次机会猜;
3.如果用户猜测数字大于系统给出的数字,打印"too big"
4.如果用户猜测数字小于系统给出的数字,打印"too small"
5.如果用户猜测的数字等于系统给出的数字,打印"恭喜中奖",
并退出循环

a = random.randint(1,100)

i=1

for i in range(1,6):
    player = int(input("请输入你要输入的数字:"))
    if (player < a):
        print("too small")
        print('你还有%d次机会' % (5 - i))
    elif (player > a):
        print("too big")
        print('你还有%d次机会'  %(5-i))
    else:
        print("恭喜,你猜对了!!!")
        print('你要猜的数字是%d' %a )
        break

else:
    print("失败,请再接再砺!!!")
    print('你要猜的数字是%d' %a)

在这里插入图片描述
在这里插入图片描述
二:做乘法题

while True:
        import random
        a = random.randint(0,10)
        b = random.randint(0,10)
        print('你要做的题目是%d * %d:'  %(a,b))
        d = int(a * b)
        c = int(input("请输入你的答案:"))
        if c==d:
            print("你的答案是正确的!")
        else:
            print("你的答案是错误的!")

在这里插入图片描述
如果不要while true:
在这里插入图片描述 三:打印乘法表

row = 1
while row <= 9:  
    col = 1  
    while col <= row:
       print('*d * %d = %d \t' %(col,row,row*col),end='')
         col += 1
    print('')
    row += 1

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/bmengmeng/article/details/94003699