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 8701651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:27:10+00:00 2026-06-13T02:27:10+00:00

Im trying to add 5 to this vector if a number in the vector

  • 0

Im trying to add 5 to this vector if a number in the vector is less then 4. I feel like im pretty close but it isnt running correctly. Can anyone give me some help adding 5 to any value less then 4 in the vector?

from pylab import * 
numberlist = [3.2,6,7.8,1,3,2.5]
def x(numberlist):
    for num in numberlist:
        if num > 4:
            print(num)
        else :
            print(num + 5)
print x([3.2,6,7.8,1,3,2.5])
  • 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-13T02:27:11+00:00Added an answer on June 13, 2026 at 2:27 am

    What you have does exactly what you’re describing. Looks like you’re new to python, possibly new to programming in general.

    The code is a bit confusing for the following reasons.

    1. You define a global variable named numberlist and assign it an array of numbers.
    2. The parameter for you function x is named numberlist again.
    3. When calling x, you pass an array of the same values you assigned to the global variable numberlist in the beginning.

    Important points to note:

    • The global variable numberlist and x‘s parameter named numberlist are two TOTALLY DIFFERENT VARIABLES. The effect you have is that the global variable numberlist isn’t accessible inside of your function x. You’re not actually using the global variable numberlist anywhere.
    • If you wanted to use the global variable numberlist and pass it to x, instead of x([3.2,6,7.8,1,3,2.5]), you would just do x(numberlist).
    • You should rename x‘s numberlist parameter to something else. mylist for example.
    • You really don’t need the import statement at the top.

    Taking those into account, your code is more readable as follows:

    def x(mylist):
        for num in mylist:
            if num > 4:
                print(num)
            else :
                print(num + 5)
    numberlist = [3.2,6,7.8,1,3,2.5]
    print x(numberlist)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add some logic in this. But I am not sure
I'm new with vectors. I'm trying to add objects to a vector. But the
I'm trying to add Modernizr to this page: http://www.alternativeradio.org/pages/test . Modernizr works fine and
I'm trying to add some share this javascript in between the head tags of
I'm trying to add a value (in this case the string I Added This)
I started by trying to add a .toggle() to this code so that the
I've encountered this problem (while trying to add SQL Server Database (.mdf) file to
I am trying to add a sqlite DB into an application using this: CoreData:
I'm trying to add a character limit clause to this white list regex approach
I am trying to add a new record to my internal table and this

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.