#让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()
标签:练习,20,函数,2023.10,数字,print,input,输入,12python
From: https://blog.51cto.com/u_16227531/7835070