A community for students.
Here's the question you clicked on:
 0 viewing
vpatel42095
 4 years ago
Python programming:
How would I plug in many different values for variables in an equation and have the program return the answer?
vpatel42095
 4 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

JonathanFichter
 4 years ago
Best ResponseYou've already chosen the best response.0You 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!

Joz
 4 years ago
Best ResponseYou've already chosen the best response.0To 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.

carlsmith
 4 years ago
Best ResponseYou've already chosen the best response.1Build 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
Ask your own question
Sign UpFind 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
 Engagement 19 Mad Hatter
 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.