1.输出九九乘法表
for i in range(1,10):
for j in range(1,i+1):
print('%d*%d=%d\t'%(j,i,i*j),end='')
print()
# 通过指定end参数的值,可以取消在末尾输出回车符,实现不换行。
2.求两个数的最大公约数
#定义一个函数,该函数返回两个数的最大公约数
def hcf(x,y):
#获取最小值
if x>y:
smaller=y
else:
smaller=x
for i in range(1,smaller+1):
if((x%i==0)and(y%i==0)):
hcf=i
return hcf
num1=int(input('输入第一个数:'))
num2=int(input('输入第二个数:'))
print('%d和%d的最大公约数为%d'%(num1,num2,hcf(num1,num2)))
3.求两个数的最小公倍数
#定义一个函数,该函数返回两个数的最小公倍数
def lcm(x,y):
#获取最大的数
if(x>y):
greater=x
else:
greater=y
#最小公倍数无上限,所以不用for循环
while(True):
if((greater%x==0)and(greater%y==0)):
lcm=greater
break
else:
greater+=1
return lcm
num1=int(input('请输入第一个数:'))
num2=int(input('请输入第二个数:'))
print('%d和%d的最小公倍数为%d'%(num1,num2,lcm(num1,num2)))
4.生成指定日期的日历
#引入日历模块
import calendar
y=int(input('请输入年份:'))
m=int(input('请输入月份:'))
#显示日历
print(calendar.month(y,m))
5.python字符串判断
str = "runoob.com"
print(str.isalnum()) # 判断所有字符都是数字或者字母 #False
print(str.isalpha()) # 判断所有字符都是字母 #False
print(str.isdigit()) # 判断所有字符都是数字 #False
print(str.islower()) # 判断所有字符都是小写 #True
print(str.isupper()) # 判断所有字符都是大写 #False
print(str.istitle()) # 判断所有单词都是首字母大写,像标题 #False
print(str.isspace()) # 判断所有字符都是空白字符、\t、\n、\r #False
str = "runoob"
print(str.isalnum()) #True
print(str.isalpha()) #True
print(str.isdigit()) #True
print(str.islower()) #True
print(str.isupper()) #True
print(str.istitle()) #True
print(str.isspace()) #True