Question

I need help on these functions PYTHON 3. The information about the functions is in the first two pics. Scenario The Pokemon franchise consists of over 60 video games, 15 movies, several TV shows, a trading card game, and even a musical. It has been around for over two decades and at this point has fans of all ages. Because of this, people have become somewhat analytical about how they play the games. To help players of the Pokemon video games, some people have created a Pokemon data set with all the useful statistics, while other people have created data sets with the Pokemons other properties (such as type). It will be your job to merge together these two data sets and give players some useful statistics and analysis of what you find CSV file: This is a file containing ASCII text where each line in the file represents one record of information, and each piece of info in the record is separated by a single comma. The very first line is the header row, which names the columns but is not part of the data. You will be given two CSV files to work with: an info file (containing information such as the Pokemons type and the generation of the game it was introduced in) as well as a stats file (containing information on how good the Pokemon is at various things, such as attack and defense) Below are two very small sample files that can be used in our project. Note: the file extension has no effect on the file contents; you can edit these files in your code editor, and you can give them any extension you want without changing the ability of your program. Its best not to use MS Excel, as it often uses several different notions of what a CSV file should be and it is easy to mess them up Example info file: ID Name Type 1 Type 2 Generation Legendary 1, Bulbasaur, Grass Poison 1, FALSE 6, Charizard Fire Flying,1 FALSE 4, Charmander Fire FALSE 169 Crobat Poison Flying,2, FALSE 146, Moltres, Fire Flying,1,TRUE 643 Reshiram Dragon Fire TRUE 641, Tornadus, (Incarnate Form Flying 5, TRUE Example stats file ID HP Attack Defense Speed 1,45,49,49,45 4,39,52,43,65 6,78,84,78, 100 146,90,100, 90,90 149,91,134, 95,80 641,79,115, 70,111 643,100,120,100, 90

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def read_info_file(filename):
d1={}
info=[]
with open(filename,"r") as f:
f.readline()#reading headers
for line in f:
line=line.replace('"','')
count=line.count(",")
if(count==6):
str=line.split(",")
str[1]=str[1]+","+str[2]
info=[a for a in str if a.count(",")==0]
else:
info=line.split(",")
d1[info[1]]=(int(info[0]),info[2],info[3],int(info[4]),info[5]=="True")
return d1


def read_stats_file(filename):
d2={}
stats=[]
with open(filename,"r") as f:
f.readline()#reading headers
for line in f:
stats=line.split(",")
d2[int(stats[0])]=(int(stats[1]),int(stats[2]),int(stats[3]),int(stats[4]))
return d2

d1=(read_info_file("info.txt"))
d2=(read_stats_file("stats.txt"))

def combine_databases(info_db,stats_db):
finaldict={}
for names in info_db:
for id in stats_db:
a,b,c,d,e=info_db[names]
f,g,h,i=stats_db[id]
if(a==id):
finaldict[names]=(a,b,c,f,g,h,i,d,e)
break

return finaldict
print("info_db :%s "%d1)
print("stats_db :%s"%d2)
print("final_db: %s" % combine_databases(d1,d2))

read stats file 19 def read_stats_file(filename): 20 21 22 E with open(filename,r) as f: 23 d2-1 stats [] f. readline()#rea

31 32 def combine_databases (info_db, stats_db): finaldict-( for names in info db: 35 E for id in stats db: a,b,c,d,e-info_db

Add a comment
Know the answer?
Add Answer to:
I need help on these functions PYTHON 3. The information about the functions is in the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Instructions Project 2: Gotta Catch ‘Em All Due: July 16 by Midnight For this...

    In C++ Instructions Project 2: Gotta Catch ‘Em All Due: July 16 by Midnight For this project you will be designing and implementing a system, in C++, to catalogue Pokémon, their trainers, and the local Pokémon gyms. Your system should act as a database and allow the user to load in multiple tables of data, run basic queries on the data, and then store the data off for later use. Additionally, sample input files will not be uploaded to Canvas,...

  • PLEASE DO IT IN PYTHON, THANK YOU! CSV file: This is a file containing plain text...

    PLEASE DO IT IN PYTHON, THANK YOU! CSV file: This is a file containing plain text where each line in the file represents one record of information, and each piece of info in the record is separated by a single comma. Luckily the values won't ever contain commas themselves for this project. But they might start or end with non visible characters (e.g. space, tab). Thus, you must remove the leading and trailing spaces when you store the data in...

  • Python 3 Coding Functions: Here is any code required to help code what is below: def...

    Python 3 Coding Functions: Here is any code required to help code what is below: def pokemon_by_types(db, types): new_db = {} for pokemon_type in types: for key in db: # iterate through all the type in types list if db[key][1] == pokemon_type or db[key][2] == pokemon_type: if key not in new_db: new_db[key] = db[key] return new_db I need help coding the functions listed below in the image: Thank you get types(db): Given a database db, this function determines all the...

  • Python: def combo(): play = True while play: x = int(input('How many people\'s information would you...

    Python: def combo(): play = True while play: x = int(input('How many people\'s information would you like to see: ')) print()    for num in range(x): name() age() hobby() job() phone() print()       answer = input("Would you like to try again?(Enter Yes or No): ").lower()    while True: if answer == 'yes': play = True break elif answer == 'no': play = False break else: answer = input('Incorrect option. Type "YES" to try again or "NO" to leave": ').lower()...

  • Python Help Please! This is a problem that I have been stuck on.I am only suppose...

    Python Help Please! This is a problem that I have been stuck on.I am only suppose to use the basic python coding principles, including for loops, if statements, elif statements, lists, counters, functions, nested statements, .read, .write, while, local variables or global variables, etc. Thank you! I am using python 3.4.1. ***( The bottom photo is a continuation of the first one)**** Problem statement For this program, you are to design and implement text search engine, similar to the one...

  • Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create...

    Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create a completed program that prompts the user for the name of a data file, and reads the contents of that data file, then creates variables in a form suitable for computing the answer to some questions. The format should be in the same manner as the attached .py file. All subsequent assignment details (.py and .csv files) can be found at this...

  • 1. You will develop a Python program to manage information about baseball players. The program will...

    1. You will develop a Python program to manage information about baseball players. The program will maintain the following information for each player in the data set: player’s name (string) team identifier (string) games played (integer) at bats (integer) runs scored (integer) hits (integer) doubles (integer) triples (integer) homeruns (integer) batting average (real) slugging percentage (real) The first nine items will be taken from a data file; the last two items will be computed by the program. The following formulas...

  • Need C programming help. I've started to work on the program, however I struggle when using...

    Need C programming help. I've started to work on the program, however I struggle when using files and pointers. Any help is appreciated as I am having a hard time comleting this code. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 100 #define MAX_NAME 30 int countLinesInFile(FILE* fPtr); int findPlayerByName(char** names, char* target, int size); int findMVP(int* goals, int* assists, int size); void printPlayers(int* goals, int* assists, char** names, int size); void allocateMemory(int** goals, int** assists, char*** names, int size);...

  • I need help with my homework assignment Linux systems keep user account information in the passwd...

    I need help with my homework assignment Linux systems keep user account information in the passwd file and the encrypted password in the shadow file. The passwd file containing account information might look like this: smithj:x:1001:1001:John Smith:/home/smithj:/bin/bash The shadow file containing password and account expiration information for users might look like this: smithj:KJDKKkkLLjjwlnttqoiybnm.:10063:0:99999:7::: The fields in the shadow file are separated by a colon, with the first field being the username and the second being the password. Under normal circumstances,...

  • any graph that show information about candida glabrata, any info is fine I just need to...

    any graph that show information about candida glabrata, any info is fine I just need to follow the requirements For your results, you will need at least two graphs. For each graph that you intend to develop, provide the following information: Graph Title * Label name for X-axis Label name for y-axis What the data in your graph will show What type of graph you intend to use (line graph, bar graph) and why

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT