Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8707409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:51:52+00:00 2026-06-13T03:51:52+00:00

Every time I run my code, it tells me that total is not defined.

  • 0

Every time I run my code, it tells me that total is not defined. I have it defined in support.py, which is then imported into stopping.py. I’ve looked for similar cases, but I can’t see why it’s telling me this. Please help!

This is stopping.py

from support import *

def main():

    def get_info():
      amplitude = float(input("Amplitude of the sine wave (in feet): "))
      period = float(input("Period of the sine wave (in feet): "))
      sign = float(input("Distance to the stop sign (in feet): "))
      nobrake = float(input("Distance needed to stop without using hand brakes (in feet): "))
      step = 9
      return amplitude, period, sign, nobrake

    get_info()

    get_distance(0, 0, 155.3, 134.71)

    print("Distance to the stop sign (in feet): 155.3")
    print("Distance needed to stop without using hand brakes (in feet): 350.5")
    print("Length of the sine wave: ", total)

main()

This is support.py

import math

def get_sine_length(amplitude, period, x_distance, step):
  x = 0.0
  total = 0.0
  last_x = 0
  last_y = 0
  while x <= x_distance + (step / 2):
     y = math.sin(2 * math.pi / period * x) * amplitude
     dist = get_distance(last_x, last_y, x, y)
     #print("distance from (", last_x, ",", last_y, ") to (", x, ",", y, ") is", dist)
     total = total + dist
     last_x = x
     last_y = y
     x = x + step
 return total

def get_distance(a, b, c, d):
   dx = c - a
   dy = d - b
   dsquared = dx**2 + dy**2
   result = math.sqrt(dsquared)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:51:53+00:00Added an answer on June 13, 2026 at 3:51 am

    total is local to get_sine_length. Since you’re returning it, to get to it you call get_sine_length and store the result.

    The problem doesn’t actually have anything to do with the import really. It would be the same if the function definition for get_sine_length was in stopping.py. Variables defined inside functions (inside a def someFunc():) are only accessible to that function unless you force them to be global. Most of the time, however, you shouldn’t declare global variables just to access normally local vars from outside a function – that is what returning is for.

    This example shows the general issue you’re running into. I’m hesitant to call it a problem, because it is actually an important language feature of python (and many other programming languages).

    >>> def func():
    ...     localVar = "I disappear as soon as func() is finished running."
    ... 
    >>> print localVar
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'localVar' is not defined
    >>> func()
    >>> print localVar
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'localVar' is not defined
    

    Think of a function as a machine that takes in certain inputs and outputs others. You generally don’t want to open up the machine- you just want to put the inputs in and get the output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue where every time I try to run a project (that
Every time I run the code below it is supposed to come up with
I have this warning every time I run my CGI-script (output is rendered by
I am getting a warning I do not fully understand every time I run
I have a spork gem issue. Every time I run the spork command I
I have a Visual Studio 2005 solution. Every time I try to run the
Every time I pull code into my repository after making changes to JS or
//This is the function that will run every time a new item is added
I have a Ruby program that, amongst other things, executes user-defined blocks of code
I'm running through the gitimmersion.com labs and every time I run a: git hist

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.