2023.10.12python练习关于函数
  9E3vfgILUe1a 2023年11月02日 40 0
#让20以内的奇数写入函数里然后输出三遍
def number():
    a = -1
    while a<19:
        a+=2
        print(a,end=" ")
b=1
while b<=3:
    b+=1
    number()
    print()



#输出5次20以内的奇数并输出5次9*9乘法表,都写入一个函数里
def www():
    x, y = 1, 1
    z = x * y
    for y in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
        z = x * y
        for x in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
            if x <= y:
                z = x * y
                print(int(x), "*", int(y), "=", int(z), "  ", end=" ")
        print()
c=1
while c<=5:
    c+=1
    print("")
    print()
    www()
    print("")
    number()



#猜数字用函数完成

def cai_shu_zi():
    import random
    n = random.randint(1, 100)
    y=1
    x = int(input("请输入要猜的数字"))
    while y<=4:
        if x==n:
            print("恭喜!")
        elif int(x)+20<int(n):
            print("猜小了20多")
            x = input("请输入要猜的数字")
            y+=1
        elif int(x)-20>int(n):
            print("猜大了20多")
            x = input("请输入要猜的数字")
            y+=1

        else:
            print("再试试")
            x = input("请输入要猜的数字")
            y+=1

cai_shu_zi()
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

9E3vfgILUe1a