*
**
***
****
*****
******
i = int(input("请输入打印的行数:"))
for j in range(1, i + 1):
print("*" * j)
i = int(input("请输入打印的行数:"))
j= 1
while j <= i:
print("*" * j)
j += 1
*
***
*****
*******
*********
***********
i = int(input("请输入打印的行数:"))
for j in range(1, i + 1):
print("*" * (2*j - 1))
i = int(input("请输入打印的行数:"))
j = 1
while j <= i:
print("*" * (2*j - 1))
j += 1
***********
*********
*******
*****
***
*
i = int(input("请输入打印行数:"))
for j in range(i, 0, -1):
print("*" * (2*j - 1))
i = int(input("请输入打印行数:"))
while i >= 0:
print("*" * (2*i -1))
i -= 1
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
i = int(input("请输入需要打印的行数:"))
for j in range(1, i // 2 + 1):
print("*" * (2*j - 1))
if i > i // 2 + 1:
for k in range(i // 2 + 1, 0, -1):
print("*" * (2*k - 1))
i = int(input("请输入需要打印的行数:"))
j = 1
while j <= i // 2:
print("*" * (2*j - 1))
j += 1
if i > i // 2:
k = i // 2 + 1
while k > 0:
print("*" * (2*k - 1))
k -= 1
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
i = int(input("请输入需要打印的行数:"))
for j in range(1, i + 1):
if j == 1 or j == i:
print("*")
else:
print("* *")
i = int(input("请输入需要打印的行数:"))
j = 1
while j <= i:
if j == 1 or j == i:
print("*")
else:
print("* *")
j += 1
*
***
* * *
* * *
* * *
***********
* * *
* * *
* * *
***
*
i = int(input("请输入需要打印的行数:"))
for j in range(1, i + 1):
if j == i // 2 + 1:
print("*" * i)
elif j == 1 or j == i:
print("*")
elif j == 2 or j == i - 1:
print("***")
else:
print("* * *")
i = int(input("请输入需要打印的行数:"))
j = 1
while j <= i:
if j == i // 2 + 1:
print("*" * i)
elif j == 1 or j == i:
print("*")
elif j == 2 or j == i - 1:
print("***")
else:
print("* * *")
j += 1
用户输入两个数a、b。如果a能被b整除或a加b大于1000,则输出a;否则输出b。
a, b = map(int, input("请输入两个数,以空格分隔:").split())
if a % b == 0 or a + b > 1000:
print(f"a = {a}")
else:
print(f"b = {b}")
a, b = map(int, input("请输入两个数,以空格分隔:").split())
c = a if a % b == 0 or a + b > 1000 else b
print(c)
请输入一个数,判断这个数是偶数还是奇数,如果使用偶数,请判断从1到该数是3的倍数有哪些,如果是奇数,请判断从1到该数是5的倍数有哪些
a = int(input("请输入一个数:"))
if a & 1 == 0: # 偶数
print(f"{a}是偶数")
for j in range(1, a + 1):
if j % 3 == 0:
print(f"1-{a}是3的倍数有:{j}")
elif a & 1 == 1: # 奇数
print(f"{a}是奇数")
for j in range(1, a + 1):
if j % 5 == 0:
print(f"1-{a}是5的倍数有:{j}")
else:
print("Error")
某商店T恤的价格为35元/件(2件9折,3件以上8折),裤子的价格为120 元/条(2条以上9折).小明在该店买了3件T恤和2条裤子,请计算并显示小明应该付多少钱?
T, K = map(int, input("请输入你要购买T恤和裤子的条数,以空格分隔:").split())
T_price = 35.0
K_price = 120.0
T_K_price = 0.0
if T == 2:
T_price = 35.0*0.9
else:
T_price = 35.0*0.8
if K > 2:
K_price = 120.0*0.9
else:
K_price = 120.0
T_K_price = T*T_price + K*K_price
print(f"小明应付的钱:{T_K_price}")
鸡兔同笼,从上面看有35个头,从下面看有94只脚,请问鸡有几只,兔有几只?
head = int(input("请输入头的个数:"))
foot = int(input("请输入脚的条数:"))
for chicken in range(1, head + 1):
rabbit = head - chicken
if (2*chicken + 4*rabbit) == foot:
print(f"兔的个数:{rabbit}, 鸡的只数:{chicken}")
else:
print("无解")
猜拳游戏:石头、剪刀、布的游戏
import random
count = 0
my_win = 0
c_win = 0
draw = 0
while True:
count += 1
compute = random.randint(1, 3)
mycode = int(input("请输入一个1~3的整数,表示出的拳头(1.石头 2.剪刀 3.布):"))
if compute == mycode:
print("点到即止,大家平手!")
draw += 1
elif (compute == 1 and mycode == 2) or (compute == 2 and mycode == 3) or (compute == 3 and mycode == 1):
print("对不起,承让")
c_win += 1
else:
print("呵呵,你也不过如此😂😂")
my_win += 1
# 每交手10次,做一次确认
if count % 10 == 0:
print(f"你们共交手{count}次,你共赢了{my_win}次,你输了{c_win}次,平手{draw}次")
choice = input("您是否确定结束游戏,如果确定结束,请输入Y或y:")
if choice.lower() == "y":
break
else:
continue
index = 0
while index <= 10:
index += 1
if index == 11:
# break
continue
print(index)
else:
print("循环中的else")
print("GAME OVER")
判断以下哪些不能作为标识符(B\D\E\F)
A、a
B、¥a
C、_12
D、$a@12
E、false
F、False
求50~150之间的质数是那些?
for num in range(50, 151):
flag = True
for i in range(2, num // 2 + 1):
if num % i == 0:
# print("不是质数")
flag = False
break
if flag:
print(f"{num}是质数")
else:
print(f"{num}是合数")
打印输出标准水仙花数,输出这些水仙花数
for num in range(100, 1000):
a = num // 100
b = num % 100 // 10
c = num % 10
if a**3 + b**3 + c**3 == num:
print(f"水仙花数为:{num}")
验证:任意一个大于9的整数减去它的各位数字之和所得的差,一定能被9整除.
# 拆位法
num = int(input("请输入一个大于9的数:"))
count = 0
while num > 0:
count += num % 10
num //= 10
if (num - count) // 9:
print("验证通过")
# 将数字转换为字符串,字符串可以求长度
num = int(input("请输入一个大于9的数:"))
count = 0
num2 = str(num)
for i in num2:
count += int(i)
if(num - count) % 9 == 0:
print("验证通过")
一个五位数,若在它的后面写上一个7,得到一个六位数A,
若在它前面写上一个7,得到一个六位数B,B是A的五倍,求此
五位数.
for i in range(10000, 1000000):
A = i * 10 + 7
B = 7 * 100000 + i
if B == 5*A:
print(f"这个五位数为:{i}")