python - Use variable in randint argument -
The total start here,
I'm writing a program that rolls the dice for the user, And I want to be able to change the number of faces of the user input per user. I can not seem to get variable amount to work as an int for the rendant () function, I get a "type error": 'str' and 'int' objects '' every time the inclusion Can not:
Exit the CIS import from random import () from the start (): Print "Do you want to roll a dice?" Like "raw_input" ("& gt;") if the choice is "yes": in the roll () option "no" alif: exit () Other: print "I do not understand, try again." Start () def (roll): print "how many faces die?" Amount_faces = raw_input ("& gt;") If zodiac_earction is int: print "face number must be an integer, try again." Print (roll): print "rolling dead ...." int (amount_face) face = randint (1, * zodiac_faces) print "you have rolled% s"% face exit () start () Any clues?
int (zodiac_office) is not changing zodiac_fices in-place You must assign functions return to the integer object:
amount_faces = int (amount_faces) amount_faces You can not use the * Ab syntax here:
face = randint (1, * amount_faces)* :face = randint (1, amount_express)There are also not tested for the right here:
If zodiac_face is int:
intone type The object is,amount_facesis just a string the input has not been convertible to find out that toint ()to throwvalueErrorYou can catch it:while correct: try zodiac_fase = Raw_input ("& gt;"): value_faces = int (amount_faces) Exclude ValueError: Print "The number of faces should be rounded Come on, try again. " Other: Print print "rolling dead ...." face = randint (1, amount_express) print "You rolled% s"% faceYou may want to check out And do not use recursive for program control.
Comments
Post a Comment