How to pass data in python3 variables to another function?
-
How would I store and pass the contents of r from main into two? It will print r if I make it r = something fixed, but how do I pass and hold variable contents into r. I tried random.getstate/setstate but it was saying "function object not subscriptable". import random from random import randrange def main(): r = random.randrange(1,13,1) print (r) r = random.randrange(1,13,1) def two(): if r==7 or r==11: print (r) else: print (r) main() two()
-
Answer:
Something like this should work #!/usr/bin/env python3 import random def main(): r= random.randrange(1,13,1) print(r) return r def two(r): if r == 7 or r == 11: print(r) else: print(r) two(main()) if you are not supposed to pass arguments, you could use a global variable. I'm not fond of that though.
meganree... at Yahoo! Answers Visit the source
Related Q & A:
- How to pass multiple parameters in a single Ajax function?Best solution by stackoverflow.com
- How to insert data from one table to another?Best solution by Stack Overflow
- how to pass data from table view to second view controller?Best solution by Stack Overflow
- How to pass data over url in modal bootstrap?Best solution by stackoverflow.com
- how to call a function in Python in another function?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.