欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python常量声明、python变量取整、python字符串格式化------python日常(一)

程序员文章站 2022-07-15 08:36:15
...

python计算CSDN积分

  • 接触python很久,看过一些教程,很多教程的举例都比较相似,套用到实际业务中时,
    经常会一时半会想不起来,故从现在从零开始,通过各种例子练习python的基础语法!
    细节方面应该还是会有各种不足,烦请大佬指正!
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : Calculate.py.py
# @Author: wujianqinjian
# @Date  : 2019/7/22
# @Desc  : 1  复习常量声明方法
#          2  复习变量取整
#          3  练习字符串格式化
#原创、转载
INITIATIVE_ORIGINAL_SCORE=10
INITIATIVE_TRANSSHIPMENT_SCORE=2
#主动评论、被动评论
INITIATIVE_COMMENT_SOCRE=1
PASSIVE_COMMENT_SCORE=1
#被动阅读数、被动点赞
PASSIVE_READ100_SCORE=1
PASSIVE_PRAISE_SCORE=1

def integration(origin,transshipment,initiative_comment,passive_comment,read,praise):
    origin_score=origin*INITIATIVE_ORIGINAL_SCORE
    transshipment_score=transshipment*INITIATIVE_TRANSSHIPMENT_SCORE
    initiative_comment_score=initiative_comment*INITIATIVE_COMMENT_SOCRE
    passive_comment_score=passive_comment*PASSIVE_COMMENT_SCORE
    # 变量取整
    read_score=int(read/100)*PASSIVE_READ100_SCORE
    praise_score=praise*PASSIVE_PRAISE_SCORE
    integration_score=origin_score+transshipment_score+initiative_comment_score+passive_comment_score+read_score+praise_score;
    #格式化方式将整形转换为字符串
    print(type(integration_score))
    integration_score='%d'%integration_score
    print(type(integration_score))
    # 格式化字符串  比较常用的 %s,
    integration_score_txt='%s 加 %s 加 %s 加 %s 加 %s 加 %s  等于  总积分: %s' %(origin_score,transshipment_score,initiative_comment_score,passive_comment_score,read_score,praise_score,integration_score)
    print(integration_score_txt)
    return integration_score

integration(11,2,22,4,3431,98)