Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

vpatel42095

  • 3 years ago

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

  • This Question is Closed
  1. JonathanFichter
    • 3 years ago
    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. Joz
    • 3 years ago
    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.

  3. carlsmith
    • 3 years ago
    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

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

    Thank you all!

  5. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

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.