Refer to the DND code (or you may refer to my solution). Rewrite the code such that each character has only one characte
Posted: Tue Jul 12, 2022 8:17 am
Refer to the DND code (or you may refer to my solution). Rewrite the code such that each character has only one characteristic: Strength. You do NOT have to include the part about writing the file... you can omit that. Each character should just have one attribute: strength. Then, create another monster class that also has a strength characteristic. Use a loop to cycle through the characters, and output who will beat the monster based upon if the character or the monster has a higher strength value. Update the strength of the monster such that every time a character attacks the monster, the monster's strength is depleted by the strength of the character. The minimum value the monster strength can be is 0. In the event of a tie, the character wins.
Please enter the number of characters you wish to have: 4 Please enter a name: Will Please enter Will's strength: 7 Please enter a name: Mike Please enter Mike's strength: 4 Please enter a name: Dustin Please enter Dustin's strength: 9 Please enter a name: Lucas Please enter Lucas's strength: 6 Please enter the name of the monster: Demogorgon Please enter the monster's strength: 20 Please enter the monster's strength: 20 Will is fighting Demogorgon Demogorgon wins Monster strength: 13 Mike is fighting Demogorgon wins Monster strength: 9 Dustin is fighting Demogorgon Dustin wins Monster strength: 0 Lucas is fighting Demogorgon Lucas wins Monster strength: 0 Demogorgon
if name q = 0 trait list = [] character list = [] number traits = int(input ("Please enter the number of traits you wish to have: ")) while (q < number traits): == 9 = 0 1 trait = input ("Please enter a trait: ") trait_list.append(trait) 9 = q + 1 main ': number characters = int (input ("Please enter the number of characters you wish to have: ")) while (q< number_characters): character = input ("Please enter a character: ") character_list.append (character) q = q + 1 total_points_allowed = int (input ("Please enter the total points you are giving per character: ")) with open ("dnd.csv", "w") as f: available") f.write(',') for t in trait list: f.write(t) f.write(',') f.write('\n') for c in character list: f.write (c) f.write(',') current points = total_points_allowed for t in trait list: print ("You have", current_points, "points + t + ": ")) int (input ("Please enter " + c + "'s current points = current points - current_p if (current_points < 0): print ("Value not allowed! Entering 0") f.write (str('0')) f.write(',') current points = current_points + current_p current_p else: = f.write (str (current_p)) f.write(',') f.write('\n')