12.13

来源:互联网 发布:php 下载文件到服务器 编辑:程序博客网 时间:2024/06/05 21:58
课堂笔记:
1.变量:无需关键字,不需要声明
2.python是一种强类型的语言:每个变量都是一个引用
3.print()换行 不换行:print(,end = “”)
4.运算符:
(1)算术运算符:+ - /(带小数) * % //(只得到整数部分)
(2)关系运算符:> < >=
(3)逻辑运算符:and or not
5.数据类型:
(1)数字:int float str bool 复数
6.分支结构:
if 条件:
    代码块
elif 条件:
    代码块
...
7.循环:
for x in range(1,X):
    循环体
斐波那契序列:1,1,2,3,5,8,13...
杨辉三角/求1-100内的所有质数
求两个数的最小公倍数/最大公约数

作业:
# 1.请用户输入一个四位数字:求此数字各个位之和(循环实现)
print('请输入一个四位数字:')
num = input()
num = int(num)
sum = 0
for i in range(1,5):
    sum+=(num%(10**i))//10**(i-1)
print(sum)
# 2.一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
print()
import math
i = 0
while True:
    tag1 = math.sqrt(i+100)
    tag2 = math.sqrt(i+168)
    if tag1%1==0 and tag2%1==0:
        print('这个整数是:{}'.format(i))
        break
    else:
        i+=1
# 3.用户输入月份,判断当前月份为几月,并输出有多少天。
# 如果用户输入2月份,则请用户输入年份,判断平年则输出28天,闰年则输出29天。
print()
print('请输入月份:')
month = input()
month = int(month)
if month==1 or month==3 or month==5 or month==7 or month==8 or month==10 or month==12:
    print('该月有31天')
elif month==4 or month==6 or month==9 or month==11:
    print('该月有30天')
else:
    print('请输入年份:')
    year = input()
    year = int(year)
    if year%4==0:
        if year%100==0:
            if year%400==0:
                print('该月有29天')
            else:
                print('该月有28天')
        else:
            print('该月有29天')
    else:
        print('该月有28天')

知识点:
1. type 和 isinstance 的区别
type()不会认为子类是一种父类类型。
isinstance()会认为子类是一种父类类型。


预习知识点:
1. break 和 continue
break:结束当前循环
continue:结束本次循环
原创粉丝点击