会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132465个问题
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程技术(旧) 20866楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 20867楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/常用类 20868楼

class Employee:

    __init_flag = True

    def __init__(self, id, name, salary):
        self.id = id
        self.name = name
        self.salary = salary

    def __add__(self, other):
        if isinstance(other, Employee):
            return self.salary+other.salary

    def input(self):
        a = 1000
        if self.id == ' ':
            if Employee.__init_flag == True:
                self.id = 1000
                Employee.__init_flag = False
                return self.id

            else:
                a = a + 1
                self.id = a
                return self.id

        else:
            return self.id

    @property
    def salary(self):
        return self.salary

    @salary.setter
    def salary(self, salary):
        if 1000 < salary < 50000:
            self.salary = salary
        else:
            print('输入错误,薪水只能在1000-50000之间')


p1 = Employee(' ', '周也', 30000)
p2 = Employee(' ', '张子枫', 40000)
print(p1+p2)
print(p2.input())
p3 = Employee(' ', '杨紫', 10000)
print(p3.input())
p4 = Employee(' ', '彭昱畅', -30000)
p4.input()
p4.set_salary()

老师,@property这里不缩进就报错

Traceback (most recent call last):

  File "E:\PycharmData\MyPython\MyPy35.py", line 42, in <module>

    p1 = Employee(' ', '周也', 30000)

  File "E:\PycharmData\MyPython\MyPy35.py", line 8, in __init__

    self.salary = salary

  File "E:\PycharmData\MyPython\MyPy35.py", line 37, in salary

    self.salary = salary

  File "E:\PycharmData\MyPython\MyPy35.py", line 37, in salary

    self.salary = salary

  File "E:\PycharmData\MyPython\MyPy35.py", line 37, in salary

    self.salary = salary

  [Previous line repeated 993 more times]

  File "E:\PycharmData\MyPython\MyPy35.py", line 36, in salary

    if 1000 < salary < 50000:

RecursionError: maximum recursion depth exceeded in comparison

但是缩进到首行就不执行了,怎么处理啊,谢谢!

Python 全系列/第一阶段:Python入门/面向对象 20870楼
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 20871楼
大数据全系列/第一阶段:Linux 操作系统/Linux操作系统概述与安装 20872楼
大数据全系列/第四阶段:Zookeeper分布式协调服务框架/ZooKeeperAPI实战 20873楼
人工智能/第六阶段:机器学习-线性分类/SVM支持向量机算法 20874楼
Python 全系列/第一阶段:Python入门/编程基本概念 20876楼

image.png

启动

celery_demo.zip

老师,celery启动,报错说找不到我的settings.py文件,怎么解决,django版本2.2,celery版本4.3。

Python 全系列/第十二阶段:Python_Django3框架/Django进阶 20877楼

SQL> select last_name,job_id from employees where ( job_id='SA_REP' or job_id='AD_PRES' ) and salary>1500;

LAST_NAME                 JOB_ID

------------------------- ----------

King                      AD_PRES

Tucker                    SA_REP

Bernstein                 SA_REP

Hall                      SA_REP

Olsen                     SA_REP

Cambrault                 SA_REP

Tuvault                   SA_REP

King                      SA_REP

Sully                     SA_REP

McEwen                    SA_REP

Smith                     SA_REP

Doran                     SA_REP

Sewall                    SA_REP

Vishney                   SA_REP

Greene                    SA_REP

Marvins                   SA_REP

Lee                       SA_REP

Ande                      SA_REP

Banda                     SA_REP

Ozer                      SA_REP

LAST_NAME                 JOB_ID

------------------------- ----------

Bloom                     SA_REP

Fox                       SA_REP

Smith                     SA_REP

Bates                     SA_REP

Kumar                     SA_REP

Abel                      SA_REP

Hutton                    SA_REP

Taylor                    SA_REP

Livingston                SA_REP

Grant                     SA_REP

Johnson                   SA_REP

31 rows selected


SQL> select last_name, job_id from employees where (job_id='SA_REP' or job_id='AD_PRES') and salary>15000;

LAST_NAME                 JOB_ID

------------------------- ----------

King                      AD_PRES

老师我这两个命令一样,为什么输出的不一样

JAVA 全系列/第三阶段:数据库编程/SQL 语言 20879楼

老师我这个坦克移动有重影,换方向时之前方向的图片都还保留着

# !/user/bin/env python3
# -*- coding: utf-8 -*-

import pygame
TEXTCOLOR=pygame.Color(255,0,0)
BG_COLOR=pygame.Color(255,0,0)
# 创建主类
class MainGame():
    window = None
    my_Tank=None
    def __init__(self):
        pass
    # 开始方法
    def startGame(self):
        # 初始化窗口
        pygame.display.init()
        screen_width = 700
        screen_height = 400
        MainGame.window = pygame.display.set_mode([screen_width, screen_height])
        MainGame.my_Tank = Tank(200, 150)
        pygame.display.set_caption('坦克大战 1.0')
        while True:
            self.getEvent()
            MainGame.window.blit(self.Textsurface('敌方坦克剩余数量:%d'%6),(10,10))
            # 调用坦克显示方法
            MainGame.my_Tank.displayTank()
            pygame.display.update()

        # 结束方法
    def endGame(self):
        print('谢谢使用,欢迎下次使用!')
        exit()
    # 左上角文字的绘制
    def Textsurface(self, text):
        pygame.font.init()
        font=pygame.font.SysFont('kaiti', 18)
        # 绘制文字信息
        textSurface=font.render(text, True, BG_COLOR)
        return textSurface
    # 获取事件
    def getEvent(self):
        eventList = pygame.event.get()
        for event in eventList:
            # 监听事件类型
            if event.type == pygame.QUIT:
                self.endGame()
            # 判断事件类型是否是按下
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_d:
                    # 切换方向
                    MainGame.my_Tank.direction='R'
                    MainGame.my_Tank.move()
                    print('按下D键,坦克向右移动')
                elif event.key == pygame.K_a:
                    MainGame.my_Tank.direction = 'L'
                    MainGame.my_Tank.move()
                    print('按下A键,坦克向左移动')
                elif event.key == pygame.K_w:
                    MainGame.my_Tank.direction = 'U'
                    MainGame.my_Tank.move()
                    print('按下W键,坦克向上移动')
                elif event.key == pygame.K_s:
                    MainGame.my_Tank.direction = 'D'
                    MainGame.my_Tank.move()
                    print('按下S键,坦克向下移动')
                elif event.key == pygame.K_SPACE:
                    print('坦克发射子弹')

class  Tank():
    #添加距离属性left,top 来确定坦克位置
    def __init__(self,left,top):
        # 保存加载的图片
        self.images={
            'U':pygame.image.load('img/p1tankU.gif'),
            'D':pygame.image.load('img/p1tankD.gif'),
            'L':pygame.image.load('img/p1tankL.gif'),
            'R':pygame.image.load('img/p1tankR.gif'),
        }
         # 方向(默认)
        self.direction='U'
        # 根据当前图片的方向获取图片
        self.image=self.images[self.direction]
        # 根据图片获取区域
        self.rect=self.image.get_rect()

        self.rect.left=left
        self.rect.top=top
        # 指定速度
        self.speed=10
        # 坦克显示方法
    def displayTank(self):
        # 获取展示对象
        self.image=self.images[self.direction]
        MainGame.window.blit(self.image,self.rect)

    # 坦克的移动
    def move(self):
        # 判断坦克的方向来进行移动
        if self.direction=='L':
            self.rect.left -= self.speed
        elif self.direction=='U':
            self.rect.top -= self.speed
        elif self.direction=='R':
            self.rect.left += self.speed
        elif self.direction=='D':
            self.rect.top += self.speed














if __name__ == '__main__':
    MainGame().startGame()


Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 20880楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637