Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

vpatel42095 Group Title

Python programming: How would I plug in many different values for variables in an equation and have the program return the answer?

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. JonathanFichter Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    You definitely want to use a loop. Either a for loop or while loop would do the trick. Each time the program goes through the loop, have it change the value of a variable. Then, before moving to the next iteration of the loop, have it test the value of the variable using something like an if statement. Conditions of the if statement(s) could tell the program to keep looping and trying new variables if it doesn't get the desired result or to stop and print or return an answer if it does get the desired result. I hope this helps in general. I'd be happy to give you more tips if you want to share more specifics about what you'd like the program to do. I'm learning, too, but I have had a lot of success with writing out what I'd like the program to do in regular words and then converting them to the appropriate code!

    • 2 years ago
  2. Joz Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    To expand slightly on JonathanFichters answer, you may want to consider whether you need to use a list or dicionary, as a way of holding all the different variables or just a range if they are consecutive or stepped numbers.

    • 2 years ago
  3. carlsmith Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Build a list of values then iterate across it with the for statement: the_list = [1, 2, 3, 401, 55.006] for n in the_list: print n * 2

    • 2 years ago
  4. vpatel42095 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thank you all!

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.