python - Determining the outcome of an encounter -


i have no idea how complete following bullet points. appreciated!!! have put code have got far below said, have no idea how incorporate code. sooooo much.

• differences between strength attributes 2 characters calculated

• difference divided 5 , rounded down create ‘strength modifier’

• process repeated skill attribute create ‘skill modifier’

• each player throws 6 sided dice.

• if scores on both dice same, no changes made

• if scores not same, player highest score adds ‘strength modifier’ strength value , ‘skill modifier’ skill value character

• player lower score on dice subtracts these modifiers strength , skill values character

• if skill value becomes negative, stored zero

• if strength value becomes 0 or negative, character dies. program should:

• allow user input strength , skill 2 characters.

• display outcome of encounter using process above. design algorithm describe process. write, test , evaluate code."""

import random  def character_attributes():     initial_value = 10     character1_strength = initial_value + (random.randint(1,12) // random.randint(1,4))     character1_skill = initial_value + (random.randint(1,12) // random.randint(1,4))     character2_strength = initial_value + (random.randint(1,12) // random.randint(1,4))     character2_skill = initial_value + (random.randint(1,12) // random.randint(1,4))      print("character 1 has strength attribute of {0}".format(character1_strength))     print("character 1 has skill attribute of {0}".format(character1_skill))     print("character 2 has strength attribute of {0}".format(character2_strength))     print("character 2 has skill attribute of {0}".format (character2_skill))      myfile = open('character_attribute_data.txt', 'w')     myfile.writelines('character 1 has strength attribute of : ')     myfile.writelines(str(character1_strength))     myfile.writelines('\n')     myfile.writelines('character 1 has skill attribute of: ')     myfile.writelines(str(character1_skill))     myfile.writelines('\n')     myfile.writelines('character 2 has strength attribute of : ')     myfile.writelines(str(character2_strength))     myfile.writelines('\n')     myfile.writelines('character 2 has strength attribute of : ')     myfile.writelines(str(character2_skill))     myfile.close()  character_attributes()  def dice_roll(number):     if number == 12:         number = random.randint(1,12)         print(number)         return number     elif number == 6:         number = random.randint(1,6)         print(number)         return number     else:         number == 4         number = random.randint(1,4)         print(number)         return number   print("12 sided")  print("6 sided")  print("4 sided")  rolls = {4: [], 6: [], 12: []} # dictionary hold rolls while true:     roll = int(input("which dice roll? --> ")) # store die size     rolls[roll].append(dice_roll(roll)) # roll , add dictionary     dorepeat=input("go again? --> ")      if dorepeat == "no":         break       print(rolls) 

as noted classes might good. if in learning head around classes let me modify dice_roll function easier understand , extend

def dice_roll(numberofsides):     if numberofsides not in set([4,6,12]):         print ("valid die size either 4, 6, or 12")         return 'invalid'     number = random.randint(1,numberofsides)     print(number)     return number 

and handle empty return

if dice_roll == 'invalid':     do_something 

you can code without else statements because same operation performed on die no matter size. saves lot of headache wondering later why define different outcomes different die size.

one thing writing code - going through right is better when go through second time.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -