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

  • SEARCH
  • Home
  • 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 9258699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:28:26+00:00 2026-06-18T12:28:26+00:00

I am a beginner in python and started to learn basics. I have a

  • 0

I am a beginner in python and started to learn basics. I have a sample program here in python

#Simple Program Python
tf=float(input("Enter total time of run in seconds "))
delt = float(input("Enter the time step of run "))
dx = float(input("Enter the value of dx "))
xf = float(input("Enter the total length of a channel "))
n =float(tf/delt)
#t =range[n]

from array import array

m = xf/dx
for i in range(0,int(n)) :
    t[i]=i*tf/n

print("THe total time of run is %r " %tf)
print("seconds")
print("The time step is %r" %delt)
print("Number of steps is %r" %n)
print("The number of space step in X direction is %r " %m)

In the for loop, when I try to assing t[i], then it throws an error “NameError: name ‘t’ is not defined”. In some stackoverflow questions, there was suggestions to use

from array import array

But I still get an error. I tried that solution from NameError: name 'array' is not defined in python. PLease help to get rid of this error.

Thanks.

Jdbaba

  • 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-18T12:28:27+00:00Added an answer on June 18, 2026 at 12:28 pm

    You have to create t before you can index into it, try this:

    m = xf/dx
    t = []
    for i in range(0,int(n)) :
        t.append(i*tf/n)
    

    You also can take out the from array import array line. You are making and using a list not an array. If you are just learning python you probably don’t need arrays and lists will do just fine.

    Actually, you can even replace the entire for loop with this:

    m = xf/dx
    t = [i*tf/n for i in range(int(n))]
    

    This version uses a list comprehension to accomplish the same thing. It is almost certainly faster and (in my opinion) easier to understand.

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

Sidebar

Related Questions

I'm a Python beginner and have just started using packages. When you're calling a
I have only started learning python recently. I would still be considered a beginner.
Python beginner here, I have a list of lists and want to refer to
Python beginner here. I have a text file that is sorted into columns: fields
Python beginner here. Let's say that I have something at the end of my
I am a beginner python learner. I created this simple program but won't display
I am a beginner in Python and I have written this simple code but
Python beginner here, so I apologize if this question has a simple answer. (I
I'm a beginner in Python. My problem is pretty simple. I have a string
beginner to python here. I have 2 nested lists that I want to merge:

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.