Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
5003CEM/Concurrent_powers_adv2
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
15 lines (12 sloc)
1004 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import concurrent.futures #imported the concurrent library | |
values = [12, 34, 22, 77, 5, 69] #created the sequence | |
power = 3 #the value of the power | |
def powers (valu, power): #creating the function with the desired parameters | |
return valu ** power #returns the power (po) of the value (val) | |
def main(): #created the main function | |
with concurrent.futures.ProcessPoolExecutor() as executor: #executes the process with the concurrent | |
for valu in values: #loops through the values one by one | |
resultado = powers (valu, power) #res is equal to the output of the powers function | |
print ('%s to the power of %s is %s' % (valu, power, resultado), '\n') #prints the output of the loop replacing the %s for the values inside the variables | |
if __name__ == '__main__': | |
main() |