I am trying to figure out how to update empty variables outside of a function in Python. The reason for this is to create a loop that queries a user about additional parameters they would be able to add.
What I have so far looks like:
param1 = ""
param 2 = ""
typeans = ['parameter 1', 'param 2']
typeansa = ['parameter 2', 'param 2']
def addparams():
while True:
again = raw_input('Would you like to add another parameter? Enter y/n: ')
if again == "n":
break
if again == "y":
additionalparams = raw_input("Would you like to add any other parameters? (Parameter 1, Parameter 2): ")
if additionalparams.lower() in typeans:
param1 = raw_input('Please enter the first search criteria: ')
param1.update() = param1+"one"
elif additionalparams.lower() in typeansa:
param2 = raw_input('Please enter the second search criteria: ')
param2.update() = param2+"two"
addparams()
addparams()
url = www.website.com/+param1+param2
The purpose of this code would be to allow me to query the user about if they had additional parameters and then add them to a url/uri. The reason I left them blank outside of the fuction is in case the user only opted to use one of the variables or a few of them (in my real code I have 7 parameters).
I understand this may not be the best way to go about this problem and would greatly appreciate any suggestions. I am new to Python and would welcome any help.
Thanks!