Coder Social home page Coder Social logo

zahidsqldba07 / python-100-days-study-notes Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dosimz/python-100-days-study-notes

0.0 0.0 0.0 12.57 MB

Python - N 天从新手到大师👩‍💻 学习笔记📒

Shell 0.12% JavaScript 5.24% Python 93.94% C 0.14% PowerShell 0.04% CSS 0.09% HTML 0.22% Vue 0.21%

python-100-days-study-notes's Introduction

这是一个关于 Python 的学习笔记 😀

  • 主要内容是根据这段时间 STAR 飙升的这个项目来学习

    我关注的时候有近七千颗 ⭐,现在已经 39987 颗 ⭐ 了

    这个项目从引初学者入门,到成为一个专业的 Python 程序员,做了很好的路线规划。 同时,这个项目里还放了‘Python 风格’、‘Python惯例’等可以提高代码质量的相关内容 📚

    一路学习过来,获益良多。

    不过,我个人觉得,它还有一些尚待改进的地方。 比如:

    • Day41 开始的‘实战 Django,这部分内容缺少完整的代码实例,我在学习过程中报错时,常渴望能在该项目的 code 文件夹中找到该部分学习内容的代码实例。

    • 目前只更新到’Day46 - 中间件的使用‘,后面内容暂时还是空白。

    https://github.com/jackfrued/Python-100-Days


  • 所以这里会有什么?

    这里主要还是用来记录我的 Python 学习过程,后期也会增加一些有趣的 Python 项目!


Python 基础心法第一层 -- 炼体篇

  • 占位符格式化数据输出字符串
a = int(input('a = '))
b = int(input('b = '))
print('%d %% %d = %d' % (a, b, a % b))

  • and or not 的使用
flag1 = True and False
flag2 = True or False
print('flag1 = ', flag1)
print('flag2 = ', flag2) 

print('flag1:false',flag1 is True)
print('flag1:false',flag1 is not False)

  • 输入年份 如果是闰年输出True 否则输出False

普通闰年:能被4整除但不能被100整除的年份为普通闰年。(如2004年就是闰年,1900年不是闰年) 世纪闰年:能被400整除的为世纪闰年。(如2000年是世纪闰年,1900年不是世纪闰年)

year = int(input('请输入年份: '))
is_leap = (year // 4 and year // 100 != 0 or year // 400)
print(is_leap)

  • 输入月收入和五险一金计算个人所得税
salary = float(input('本月收入: '))
insurance = float(input('五险一金: '))
diff = salary - insurance - 3500
if diff <= 0:
	rate = 0
	deduction = 0
elif diff < 1500:
	rate = 0.03
	deduction = 0
elif diff < 4500:
	rate = 0.1
	deduction = 105
elif diff < 9000:
	rate = 0.2
	deduction = 555
elif diff < 35000:
	rate = 0.25
	deduction = 1005
elif diff < 55000:
	rate = 0.3
	deduction = 2755
elif diff < 80000:
	rate = 0.35
	deduction = 5505
else:
	rate = 0.45
	deduction = 13505
tax = abs(diff * rate - deduction)
print('个人所得税: ¥%.2f元' % tax)
print('实际到手收入: ¥%.2f元' % (diff + 3500 - tax))

  • 打印乘法口诀表
for i in range(1,10):
    for j in range(1, i + 1):
        print('%d * %d = %d' % (i, j, i * j),  end = '\t')
    print()

  • 输入一个正整数判断它是不是素数
from math import sqrt

num = int(input('请输入一个正整数: '))
end = int(sqrt(num))  # 平方跟函数 sqrt
is_prime = True
for i in range(2, end + 1):
    if num % i == 0:
        is_prime = False
if is_prime and num != 1:
    print('%d 是素数' % num)
else:
    print('%d 不是素数' % num)

  • 输入两个正整数,计算最大公约数和最小公倍数
x = int(input('x = '))
y = int(input('y = '))
if x > y:
    (x, y) = (y, x)
for factor in range(x, 0, -1):
    if x % factor == 0 and y % factor == 0:
        print('%d 和 %d 的最大公约数是 %d' % (x, y, factor))
        print('%d 和 %d 的最小公倍数是 %d' % (x, y, x * y // factor))
        break

  • 打印三角形图案
*
**
***
****
*****

*
**
***
****
*****

    *
   ***
  *****
 *******
*********
row = int(input('请输入打印星的行数'))
for i in range(row):
    # print('*' * (i + 1), end = '/n') end 默认为'/n'
    print('*' * (i + 1))

for i in range(row):
    print(' ' * (row - i - 1) + '*' * (i + 1))

for i in range(row):
    print(' ' * (row - i - 1)  + '*' * (2 * i + 1))

  • 寻找水仙花数 判断规则: 一个三位自幂数(13 + 53 + 3**3 = 153) 寻找范围: 三位数(100~999)
for i in range(99, 1000):
    one = i // 100
    two = i // 10 % 10
    three = i % 10
    if (one**3 + two**3 + three**3 == i):
        print("水仙数! >>>" + str(i))

  • 寻找完美数 判断规则: 一个恰好等于它自身的真因子(除了自身以外的所有约数)之和 > 约数: 余为零
from functools import reduce
def add(x, y):
    return x + y

lists = []
n = int(input('请输入一个数来判断...(例如:6;28;496;8128;33550336)'))
for factor in range(1, n-1):
    if n % factor == 0:
        lists.append(factor)
if reduce(add, lists) == n:
    print("完美数!" + str(n))
else:
    print('正常数  -_-`')

  • 百鸡百钱 判断规则: 公鸡五钱,母鸡三钱,三小鸡一钱.百钱买百鸡. a: 公鸡, b: 母鸡, c: 小鸡
for a in range(20):
    for b in range(33):
        if (100-a-b)/3 + 5*a + 3*b == 100:
            print('百钱百鸡!')
            print('公鸡', a)
            print('母鸡', b)
            print('小鸡', 100-a-b) 

  • 题目 :

5个人(ABCDE)夜间合伙捕鱼,然后睡去,清晨依次醒来分鱼 A - 把鱼分成5份扔掉多的一条拿走自己的那份 B - 把鱼分成5份扔掉多的一条拿走自己的那份 C - 把鱼分成5份扔掉多的一条拿走自己的那份 D - 把鱼分成5份扔掉多的一条拿走自己的那份 E - 把鱼分成5份扔掉多的一条拿走自己的那份 五人至少捕到多少条鱼?

fish = 1
while True:
    total = fish
    is_enouge = True
    for _ in range(5):
        if total % 5 == 1:
            total = (total-1) // 5 * 4
        else:
            is_enouge = False
            break
            print('这鱼不对')
    if is_enouge:
        print('这鱼%d条' % fish)
        break
    fish += 1

  • 斐波那契数列 像这样: 1,1,2,3,5,8,13,21,34,...
def fib(n):
    a, b = 1, 1
    while a < n:
        print(a, end = ' ')
        a, b = b, a + b
    # print("")
fib(2)

  • 回文素数
def is_prime(numSpaces):
    prime = True
    for j in range(2,numSpaces-1):
        if numSpaces % j == 0:
            prime = False
    if numSpaces < 11:
        prime = False        
    return prime
# print(is_prime(2))
num = 1
while True:
    numSpace = num
    if str(numSpace)[::-1] == str(numSpace) and is_prime(numSpace):
        print('这是回文', numSpace)
    num += 1

  • Craps 赌博游戏

游戏规则: 玩家掷两个骰子,如果第一次点数和为 7 或 11,则玩家胜;如果点数和为2、3 或 12,则玩家输庄家胜。 若和为其他点数,则记录第一次的点数和,然后玩家继续掷骰子,若和第一次点数的和相同,玩家赢;若和为7,则庄家赢。

import random
x = random.randint(1,7)
y = random.randint(1,7)
one = x + y
print(one)
if (one == 7) or (one == 11):
    print('Player WIN')
elif (one == 2) or (one == 3) or (one == 12):
    print('Boss WIN')
else:
    while True:
        a = random.randint(1,7)
        b = random.randint(1,7)
        if a + b == one:
            print(a + b)
            print('Player WIN')
            break
        elif a + b == 7:
            print(a + b)
            print('Boss WIN')
            break
  • 实现计算最大公约数和最小公倍数的函数
def gcd(x, y):
    (x, y) = (y, x) if x > y else (x, y)
    for factor in range(x, 0, -1):
        if x % factor == 0 and y % factor == 0:
            return factor

def lcm(x, y):
    return x * y // gcd(x, y)
  • 实现一个回文判断函数
def is_palindrome(num):
    temp = num
    total = 0
    while temp > 0:
        total = total * 10 + temp % 10
        temp //= 10
    return num == total

python-100-days-study-notes's People

Contributors

dosimz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.