Create a new program in Mu and save it as ps4.5.3.py and take the code below and fix it as indicated in the comments:
# In the Pokemon video game series, every Pokemon has six # stats: HP, Attack, Defense, Special Attack, Special Defense, # and Speed. # # Write a function called total_stats that will take as input # a list of dictionaries. Each dictionary will have seven # key-value pairs: # # - name: a Pokemon's name # - hp, attack, defense, special attack, special defense, # and speed: an integer representing that Pokemon's stat # in that category # # Your function should return a single dictionary. The keys # of the dictionary should be the Pokemon names from the # original list, and the values should be the _total_ stats # for each Pokemon (add HP, Attack, Defense, Special Attack, # Special Defense, and Speed). # # For example, if this was one of the dictionaries in the # original list: # # {"name": "Bulbasaur", "hp": 45, "attack": 49, "defense": 49, # "special attack": 65, "special defense": 65, "speed": 45} # # Then one of the key-value pairs in the dictionary you # return would be: "Bulbasaur": 318 (45 + 49 + 49 + 65 + 65 + # 45 = 318). # Add your function here! # Below are some lines of code that will test your function. # You can change the value of the variable(s) to test your # function with different inputs. # # If your function works correctly, this will originally # print (although the order of the keys may vary): # {'Bulbasaur': 318, 'Charmander': 309, 'Squirtle': 314} starters = [{"name": "Bulbasaur", "hp": 45, "attack": 49, "defense": 49, "special attack": 65, "special defense": 65, "speed": 45}, {"name": "Charmander", "hp": 39, "attack": 52, "defense": 43, "special attack": 60, "special defense": 50, "speed": 65}, {"name": "Squirtle", "hp": 44, "attack": 48, "defense": 65, "special attack": 50, "special defense": 64, "speed": 43}] print(total_stats(starters))
# Python Code
# In the Pokemon video game series, every Pokemon has six
# stats: HP, Attack, Defense, Special Attack, Special Defense,
# and Speed.
#
# Write a function called total_stats that will take as input
# a list of dictionaries. Each dictionary will have seven
# key-value pairs:
#
# - name: a Pokemon's name
# - hp, attack, defense, special attack, special defense,
# and speed: an integer representing that Pokemon's stat
# in that category
#
# Your function should return a single dictionary. The keys
# of the dictionary should be the Pokemon names from the
# original list, and the values should be the _total_ stats
# for each Pokemon (add HP, Attack, Defense, Special Attack,
# Special Defense, and Speed).
#
# For example, if this was one of the dictionaries in the
# original list:
#
# {"name": "Bulbasaur", "hp": 45, "attack": 49, "defense": 49,
# "special attack": 65, "special defense": 65, "speed": 45}
#
# Then one of the key-value pairs in the dictionary you
# return would be: "Bulbasaur": 318 (45 + 49 + 49 + 65 + 65 +
# 45 = 318).
# Add your function here!
def total_stats(starters_list):
my_dict = {}
for index in range(len(starters_list)):
total = 0
my_key = ""
for key in starters_list[index]:
if key == "name":
my_key = starters_list[index][key]
else:
total += starters_list[index][key]
my_dict[my_key] = total
return my_dict
# Below are some lines of code that will test your function.
# You can change the value of the variable(s) to test your
# function with different inputs.
#
# If your function works correctly, this will originally
# print (although the order of the keys may vary):
# {'Bulbasaur': 318, 'Charmander': 309, 'Squirtle': 314}
starters = [{"name": "Bulbasaur", "hp": 45, "attack": 49, "defense": 49, "special attack": 65, "special defense": 65, "speed": 45},
{"name": "Charmander", "hp": 39, "attack": 52, "defense": 43, "special attack": 60, "special defense": 50, "speed": 65},
{"name": "Squirtle", "hp": 44, "attack": 48, "defense": 65, "special attack": 50, "special defense": 64, "speed": 43}]
print(total_stats(starters))
# output
//If you need any help regarding this solution.... please leave a comment......... thanks
Create a new program in Mu and save it as ps4.5.3.py and take the code below...
Create a new program in Mu and save it as ps4.5.1.py and take the code below and fix it as indicated in the comments: # Write a function called phonebook that takes two lists as # input: # # - names, a list of names as strings # - numbers, a list of phone numbers as strings # # phonebook() should take these two lists and create a # dictionary that maps each name to its phone number. For #...
Create a new program in Mu and save it as ps4.5.2.py and take the code below and fix it as indicated in the comments: # Do not change the line of code below. It's at the top of # the file to ensure that it runs before any of your code. # You will be able to access french_dict from inside your # function. french_dict = {"me": "moi", "hello": "bonjour", "goodbye": "au revoir", "cat": "chat", "dog": "chien", "and": "et"} #...
Create a new program in Mu and save it as ps4.3.2.py and take the code below and fix it as indicated in the comments: # Write a function called find_max_sales. find_max_sales will # have one parameter: a list of tuples. Each tuple in the # list will have two items: a string and an integer. The # string will represent the name of a movie, and the integer # will represent that movie's total ticket sales (in millions # of...
Create a new program in Mu and save it as ps4.3.1.py and take the code below and fix it as indicated in the comments: # Write a function called grade_scantron. grade_scantron should # take as input two lists: answers and key. Each list contain # strings. Each string will be only one letter, a character # from A to E. grade_scantron should return how many questions # the student got "right", where a student gets a question # right if...
Create a new program in Mu and save it as ps2.4.3.py Take the code below and fix it as indicated in the comments: Level = 50 Attack = 125 Defense = 110 Power = 60 Modifier = 1 # You may modify the lines of code above, but don't move them! # Your code should work with different values for the variables. # In the Pokemon game franchise, damage is calculated using this formula found here: # https://bulbapedia.bulbagarden.net/wiki/Damage # #...
Create a new program in Mu and save it as ps4.4.1.py and take the code below and fix it as indicated in the comments: # Write a function called "save_leaderboard" that accepts a # single list of tuples as a parameter. The tuples are of the # form (leader_name, score) # The function should open a file called "leaderboard.txt", # and write each of the tuples in the list to a line in the file. # The name and score...
Create a new program in Mu and save it as ps4.3.3.py and take the code below and fix it as indicated in the comments: # Imagine you're writing some code for an exercise tracker. # The tracker measures heart rate, and should display the # average heart rate from an exercise session. # # However, the tracker doesn't automatically know when the # exercise session began. It assumes the session starts the # first time it sees a heart rate...
Create a new program in Mu and save it as ps3.2.1.py and take the code below and fix it as indicated in the comments: hour = 3 minute = 45 # You may modify the lines of code above, but don't move them! # When you Submit your code, we'll change these lines to # assign different values to the variables. # Around Georgia Tech, there are plenty of places to get a # late night bite to eat. However,...
Create a new program in Mu and save it as ps3.4.1.py and take the code below and fix it as indicated in the comments: # Write a function called hide_and_seek. The function should # have no parameters and return no value; instead, when # called, it should just print the numbers from 1 through 10, # follow by the text "Ready or not, here I come!". Each # number and the message at the end should be on its own...
Create a new program in Mu and save it as ps4.2.1.py and take the code below and fix it as indicated in the comments: # Write function called third_character that accepts a # string as an argument and returns the third character # of the string. If the user inputs a string with fewer than # 3 characters, return "Too short". # Write your function here! # Below are some lines of code that will test your function. # You...