python 2025/7/28
输出
自己试着写了一些简单逻辑
99乘法表
i=1
while i<=9:j=1while j<=i:print(f"{j}*{i}={i*j}\t",end='')j+=1print()i+=1
sum
print(sum(1,2))
a个数
str=input("请输入字符串")
sum=0
for x in str:if x=="a":sum+=1
print(sum)
fuc
def sum(num1,num2,num3):return num1+num2+num3res=sum(1,2,3)
print(res)
猜数
import random
num=random.randint(1,100)
gs=int(input("请输入数字:"))
while gs!=num:if gs<num:print("猜小了")else:print("猜大了")gs=int(input("请输入数字:"))
print("猜对了")
偶数个数
sum=0
for x in range (1,100):if x%2==0:sum+=1
print(sum)
翻转
s="吧好,的对"
s1=s[::-1]
s2=s1.split(",")
print(s2)
排序
def sort(arr):# 大->小n=len(arr)for i in range(n):for j in range(0,n-i-1):if arr[j]<arr[j+1]:arr[j],arr[j+1]=arr[j+1],arr[j]print(arr)
arr=[1,4,6,3,2,8]
sort(arr)