Python 参数丢失,即使给定了2个变量
我需要在对象学校中存储分区数和类数 file1.pyPython 参数丢失,即使给定了2个变量,python,python-3.7,Python,Python 3.7,我需要在对象学校中存储分区数和类数 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 (V
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)
错误:
回溯(最近一次呼叫最后一次):
文件“ttmain.py”,第24行,在
pak=classes.School.mouse(类的数量,分区的数量)
TypeError:mouse()缺少1个必需的位置参数:“num\u of\u divisions”
另外,我需要鼠标返回类的num_值和分区的num_值。您需要先创建
学校的类的实例,然后才能访问鼠标功能
schoolObj = file1.School()
return_value = schoolObj.mouse(num_of_class, num_of_divisions)
print(return_value)
您应该首先创建类的实例variable=file1.School()
,然后使用它的方法variable.takla(类的num\u,分区的num\u)
,然后Python将它作为School.takla(变量,类的num\u,分区的num\u)运行
-因此它将变量
分配给self
,并将其他值分配给num\u of_class,num\u of_divisions
中def takla(…)
的变量。顺便说一句:您的错误消息显示了classes.School.takla
的问题,但您没有在代码中显示它。@furas谢谢,我更改了问题的方法名,但在错误消息中忘记更改它。
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'
schoolObj = file1.School()
return_value = schoolObj.mouse(num_of_class, num_of_divisions)
print(return_value)