I am new to programming and the forums, teaching my self python. I would like some assistance in a D20 dice rolling system, everything worked in my code until I put everything in to functions. Now I get an error "local variable 'selectamount' referenced before assignment".

I have images linked and code I do not need some one to write the code for me I just need help in understanding what I am doing wrong. Thank you in advanced for any and all help.

https://goo.gl/photo...z4FoFycr3Eh7fu6

https://goo.gl/photo...8tDM1PxYzoLtkm7

https://goo.gl/photo...jjxG65ZHBArmYNA

import random #user input def user_input(): global selectdice selectdice = input("Select dice to use: d2, d4, d6, d8, d10, d12, d20, d100: ") global selectamount selectamount = int(input("How may would you like to roll? 1-100: ")) selectamount -= 1 #functions user_input() def ran_d2(): d2 = random.randint(1, 2) print ("you roll a d2:", ">>>",d2,"<<<") def ran_d4(): d4 = random.randint(1, 4) print ("you roll a d4:", ">>>",d4,"<<<") def ran_d6(): d6 = random.randint(1, 6) print ("you roll a d6:", ">>>",d6,"<<<") def ran_d8(): d8 = random.randint(1, 8) print ("you roll a d8:", ">>>",d8,"<<<") def ran_d10(): d10 = random.randint(1, 10) print ("you roll a d10:", ">>>",d10,"<<<") def ran_d12(): d12 = random.randint(1, 12) print ("you roll a d12:", ">>>",d12,"<<<") def ran_d20(): d20 = random.randint(1, 20) print ("you roll a d20:", ">>>",d20,"<<<") def ran_d100(): d100 = random.randint(1, 100) print ("you roll a d100:", ">>>",d100,"<<<") #if statments. def main(): if selectdice == "d2": ran_d2() while selectamount > 0: selectamount -= 1 ran_d2() if selectdice == "d4": ran_d4() while selectamount > 0: selectamount -= 1 ran_d4() if selectdice == "d6": ran_d6() while selectamount > 0: selectamount -= 1 ran_d6() if selectdice == "d8": ran_d8() while selectamount > 0: selectamount -= 1 ran_d8() if selectdice == "d10": ran_d10() while amount() > 0: selectamount -= 1 ran_d10() if selectdice == "d12": ran_d12() while selectamount > 0: selectamount -= 1 ran_d2() if selectdice == "d20": ran_d20() while selectamount > 0: selectamount -= 1 ran_d20() if selectdice == "d100": ran_d100() while selectamount > 0: selectamount -= 1 ran_d100() #user_input() main()

This post has been edited by **macosxnerd101**: 20 February 2016 - 12:58 PM

Reason for edit:: Renamed title to be more descriptive