Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

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

Computer Science
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SIGN UP FOR FREE
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!
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.
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

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Thank you all!

Not the answer you are looking for?

Search for more explanations.

Ask your own question