从Python下降距离开始

时间:2018-11-29 20:20:38

标签: python

对于这个问题,我想是从falling_distance函数取回电表。我似乎无法获得变量d的计算结果。它只是给我这些我从未见过的字母和数字,这是我的代码:

gravity = 9.8
def falling_distance(fall):
    d = (1/2) * gravity * (fall**2)
    return distance
def main():
  print('Seconds\tDistance')
  print('------------------')
  for sec in range(1, 11):
     print(sec,'\t', falling_distance)
main()

输出:

Seconds Distance
------------------
1    <function falling_distance at 0x7f04ab566c80>
2    <function falling_distance at 0x7f04ab566c80>
3    <function falling_distance at 0x7f04ab566c80>

1 个答案:

答案 0 :(得分:4)

您从未调用过函数-而是打印了 function 值,该值是Python对象引用。

epsiloni

您还必须返回计算出的值-使用 <input id="fileinput" name="arquivo[]" type="file" multiple="multiple" onchange="FileDetails()"/> <var id="file_List"></var> <button type="button" onclick="Click()">Click Me!</button> <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script> <script> // simple routine to put content of file input files into memory G_Array = []; G_Cont_Upload = 0; function Click() { var a = 1; // this is only to check the content of global variable as google chrome does not stop inside f_ReadFile } function FileDetails() { var file_arr = []; if (typeof (FileReader) != "undefined") { var files = $('#fileinput')[0].files; var reader = []; for (var i = 0; i < files.length; i++) { var FileDet = files[i]; var name = FileDet.name; var Size = FileDet.size; var Obj = {Name: FileDet.name, SizeInicial : FileDet.size}; G_Array.push(Obj); reader[i] = new FileReader(); function f_ReadFile(e) { var content = e.target.result; G_Array[G_Cont_Upload].SizeAtual = content.length; G_Array[G_Cont_Upload].Content = content; // content base 64 G_Cont_Upload++; } reader[i].onload = f_ReadFile; reader[i].readAsDataURL(FileDet); } } else { alert("This browser does not support HTML5 FileReader."); } } </script> </body> Traceback (most recent call last): File "e:\venvs\django_tutorial_venv\lib\site-packages\django\utils\module_loading.py", line 20, in import_string return getattr(module, class_name) AttributeError: module 'django.contrib.auth.password_validation' has no attribute ' UserAttributeSimilarityValidator' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\password_validation.py", line 26, in get_password_validators klass = import_string(validator['NAME']) File "e:\venvs\django_tutorial_venv\lib\site-packages\django\utils\module_loading.py", line 24, in import_string ) from err ImportError: Module "django.contrib.auth.password_validation" does not define a " UserAttributeSimilarityValidator" attribute/class During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "e:\venvs\django_tutorial_venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line utility.execute() File "e:\venvs\django_tutorial_venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "e:\venvs\django_tutorial_venv\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 59, in execute return super().execute(*args, **options) File "e:\venvs\django_tutorial_venv\lib\site-packages\django\core\management\base.py", line 353, in execute output = self.handle(*args, **options) File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 163, in handle validate_password(password2, self.UserModel(**fake_user_data)) File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\password_validation.py", line 44, in validate_password password_validators = get_default_password_validators() File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\password_validation.py", line 19, in get_default_password_validators return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS) File "e:\venvs\django_tutorial_venv\lib\site-packages\django\contrib\auth\password_validation.py", line 29, in get_password_validators raise ImproperlyConfigured(msg % validator['NAME']) django.core.exceptions.ImproperlyConfigured: The module in NAME could not be imported: django.contrib.auth.password_validation. UserAttributeSimilarityValidator. Check your AUTH_PASSWORD_VALIDATORS setting. 。经过这两个更改,您的程序可以很好地运行:

for sec in range(1, 11):
    print(sec,'\t', falling_distance(sec))