即使给出了2个变量,也缺少参数

时间:2019-11-08 20:54:54

标签: python python-3.7

我需要在对象School中存储num_of_divvisions和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的值

1 个答案:

答案 0 :(得分:1)

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

schoolObj = file1.School()
return_value = schoolObj.mouse(num_of_class, num_of_divisions)
print(return_value)