即使提供了2个变量,参数仍然丢失

问题描述 投票:0回答:1

我需要在对象School中存储num_of_vision和num_of_classes

file1.py

import file1

name_of_school=input("Enter name of Schoool\n")
printschool=f"Your School's name is {name_of_school}"
print(printschool)

try:
   num_of_class=int(input("How many class are there in your School?\n"))
except (ValueError, TypeError) as okok:
   print("Please Enter a valid number")
else:
    if num_of_class<=0:
        print("Number cannot be zero or less")
    else:
        printvalue=f"Number of class in school are {num_of_class}"
        print(printvalue)

num_of_divisions=[]
for divisionloop in range(num_of_class):
    divisionloop=divisionloop+1
    num_of_divisions.append(int(input("Enter number of Divisions for class %d:"%(divisionloop))))

pak=file1.School.mouse(num_of_class, num_of_divisions)
print(pak)

fil2.py下面的文件是一个模块

class School:
    def mouse(self, num_of_class, num_of_divisions):
        print(num_of_class and num_of_divisions)
        self.num_of_class=num_of_class
        self.num_of_divisions=num_of_divisions
        return num_of_class
Error :
Traceback (most recent call last):
  File "ttmain.py", line 24, in <module>
    pak=classes.School.mouse(num_of_class, num_of_divisions)
TypeError: mouse() missing 1 required positional argument: 'num_of_divisions'

加上我需要鼠标同时返回num_of_class和num_of_divisions个值

python python-3.7
1个回答
1
投票

您需要先创建School类的实例,然后才能访问鼠标功能。

© www.soinside.com 2019 - 2024. All rights reserved.