Question

In: Computer Science

The file pokedex.txt contains partial information about 31 Pokémon that mostly come from this Pokédex. Assignment...

  • The file pokedex.txt contains partial information about 31 Pokémon that mostly come from this Pokédex.

Assignment

  • Using pokedex.py as a starting point, supply the missing functions such that interaction with a user could produce this transcript.

Pokedex.py:

1,bulbasaur,318,grass,poison
2,ivysaur,405,grass,poison
3,venusaur,525,grass,poison
4,charmander,309,fire
5,charmeleon,405,fire
6,charizard,534,fire,flying
7,squirtle,314,water
8,wartortle,405,water
9,blastoise,530,water
10,caterpie,195,bug
11,metapod,205,bug
12,butterfree,395,bug,flying
13,weedle,195,bug,poison
14,kakuna,205,bug,poison
15,beedrill,395,bug,poison
16,pidgey,251,normal,flying
17,pidgeotto,349,normal,flying
18,pidgeot,479,normal,flying
19,rattata,253,normal
20,raticate,413,normal
21,spearow,262,normal,flying
22,fearow,442,normal,flying
23,ekans,288,poison
24,arbok,448,poison
25,pikachu,320,electric
26,raichu,485,electric,psychic
27,sandshrew,300,ground
28,sandslash,450,ground
29,nidoran,275,poison
30,nidorina,365,poison
810,yeet,777,steel,fire,water,grass,electric,psychic,ice,dragon,dark,fairy,???

Transcript:

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 1

The Pokedex
-----------
Number: 1, Name: Bulbasaur, CP: 318: Type: grass and poison
Number: 2, Name: Ivysaur, CP: 405: Type: grass and poison
Number: 3, Name: Venusaur, CP: 525: Type: grass and poison
Number: 4, Name: Charmander, CP: 309: Type: fire
Number: 5, Name: Charmeleon, CP: 405: Type: fire
Number: 6, Name: Charizard, CP: 534: Type: fire and flying
Number: 7, Name: Squirtle, CP: 314: Type: water
Number: 8, Name: Wartortle, CP: 405: Type: water
Number: 9, Name: Blastoise, CP: 530: Type: water
Number: 10, Name: Caterpie, CP: 195: Type: bug
Number: 11, Name: Metapod, CP: 205: Type: bug
Number: 12, Name: Butterfree, CP: 395: Type: bug and flying
Number: 13, Name: Weedle, CP: 195: Type: bug and poison
Number: 14, Name: Kakuna, CP: 205: Type: bug and poison
Number: 15, Name: Beedrill, CP: 395: Type: bug and poison
Number: 16, Name: Pidgey, CP: 251: Type: normal and flying
Number: 17, Name: Pidgeotto, CP: 349: Type: normal and flying
Number: 18, Name: Pidgeot, CP: 479: Type: normal and flying
Number: 19, Name: Rattata, CP: 253: Type: normal
Number: 20, Name: Raticate, CP: 413: Type: normal
Number: 21, Name: Spearow, CP: 262: Type: normal and flying
Number: 22, Name: Fearow, CP: 442: Type: normal and flying
Number: 23, Name: Ekans, CP: 288: Type: poison
Number: 24, Name: Arbok, CP: 448: Type: poison
Number: 25, Name: Pikachu, CP: 320: Type: electric
Number: 26, Name: Raichu, CP: 485: Type: electric and psychic
Number: 27, Name: Sandshrew, CP: 300: Type: ground
Number: 28, Name: Sandslash, CP: 450: Type: ground
Number: 29, Name: Nidoran, CP: 275: Type: poison
Number: 30, Name: Nidorina, CP: 365: Type: poison
Number: 810, Name: Yeet, CP: 777: Type: steel and fire and water and grass and electric and psychic and ice and dragon and dark and fairy and ???

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 2
Enter a Pokemon name: RAICHU
Number: 26, Name: Raichu, CP: 485: Type: electric and psychic

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 2
Enter a Pokemon name: raichump
There is no Pokemon named raichump

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 3
Enter a Pokemon number: 26
Number: 26, Name: Raichu, CP: 485: Type: electric and psychic

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 3
Enter a Pokemon number: 34
There is no Pokemon number 34

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 4
Enter a Pokemon type: Normal
Number of Pokemon that contain type normal = 7

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 4
Enter a Pokemon type: ???
Number of Pokemon that contain type ??? = 1

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 4
Enter a Pokemon type: unknown
Number of Pokemon that contain type unknown = 0

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 5
Average Pokemon combat points = 370.71

1. Print Pokedex
2. Print Pokemon by Name
3. Print Pokemon by Number
4. Count Pokemon with Type
5. Print Average Pokemon Combat Points
6. Quit

Enter a menu option: 6
Thank you.  Goodbye!

Grading - 100 points

  • 20 points. The class Pokemon is defined (2 points) with the appropriate six methods (3 points each).
  • 5 points. The function print_menu is correct.
  • 10 points. The function print_pokedex is correct.
  • 10 points. The function lookup_by_name is correct when the Pokémon is present (7 points) and absent (3 points).
  • 10 points. The function lookup_by_number is correct when the number is present (7 points) and absent (3 points).
  • 10 points. The function total_by_type is correct when the type is present (7 points) and absent (3 points).
  • 10 points. The function average_hit_points is correct.
  • 10 points. The format of the output matches the format of the output in the transcript exactly. (2 points for each type of difference up to 10 points.)
  • 15 points - The Python solution is properly commented, easy to understand and does not contain unnecessary code. (3 points for each type of improvement up to 15 points.)

Solutions

Expert Solution

Code:

# -----------------------------

# The Joy and Beauty of Data

# Assignment 3: Pokedex

# Your Name:

# Date:

# -----------------------------

import string

# -----------------------------

def createPokedex(filename):

    pokedex = {}

    file = open(filename, "r")

    for pokemon in file:

        pokelist = pokemon.strip().split(",")

        index = int(pokelist.pop(0))

        pokedex[index] = [pokelist.pop(0)]          # name

        pokedex[index] += [int(pokelist.pop(0))]    # hit points

        pokedex[index] += [pokelist.pop(0)]         # type

        if len(pokelist) == 1:

            pokedex[index] += [pokelist.pop(0)]     # optional second type

    return pokedex

# -----------------------------

def print_pokedex(pokedex):

    print("\n------ The Pokedex --------\n")

    for i in pokedex:

        list = pokedex.get(i)

        n = len(list)

        if n == 3:

            print("Number = ", i, "Name: ", list[0], "CP: ", list[1] , "Type: " + list[2])

        if n == 4:

            print("Number = ", i, "Name: ", list[0], "CP: ", list[1] , "Type: " + list[2] + " and " + list[3])

   print()

def getChoice(low, high, message):

    legal_choice = False

    while not legal_choice:

        legal_choice = True

        answer = input(message)

        for character in answer:

            if character not in string.digits:

                legal_choice = False

                print("That is not a number, try again.")

                break

        if legal_choice:

            answer = int(answer)

            if (answer < low) or (answer > high):

                legal_choice = False

                print("That is not a valid choice, try again.")

    return answer

   

def lookup_by_number(pokedex, number):

    if number in pokedex:

        list = pokedex.get(number)

        n = len(list)

        if n == 3:

            print("Number = ", number, "Name: ", list[0], "CP: ", list[1] , "Type: " + list[2])

        if n == 4:

            print("Number = ", number, "Name: ", list[0], "CP: ", list[1] , "Type: " + list[2] + " and " + list[3])

        print()

    else:

        print("Invalid number!\n")

   

def lookup_by_name(pokedex, name):

    found = 0

    for i in pokedex:

        list = pokedex.get(i)

        if list[0].lower() == name.lower():

            found = 1

            n = len(list)

            if n == 3:

                print("Number = ", i, "Name: ", list[0], "CP: ", list[1] , "Type: " + list[2])

            if n == 4:

                print("Number = ", i, "Name: ", list[0], "CP: ", list[1] , "Type: " + list[2] + " and " + list[3])

            print()

    if found == 0:

        print("Invalid name!\n")

       

def total_by_type(pokedex, type):

    count = 0

    for i in pokedex:

        list = pokedex.get(i)

        n = len(list)

        if n == 4:

            if ((list[2].lower() == type.lower()) or (list[2].lower() == type.lower())):

                count = count + 1

        if n == 3:

            if (list[2] == type):

                count = count + 1

    print("Number of pokemon of given type = ", count)

    print()

   

def average_hit_points(pokedex):

    count = 0

    for i in pokedex:

        list = pokedex.get(i)

        count = count + list[1]

    avg = count / 30

    print("Average hit points = %.2f" %avg)

    print()

   

def print_menu():

    print("1. Print Pokedex")

    print("2. Print Pokemon by Name")

    print("3. Print Pokemon by Number")

    print("4. Count pokemon by type")

    print("5. Print Average Hit Points")

    print("6. Quit")

# -----------------------------

def main():

    pokedex = createPokedex("pokedex.txt")

    choice = 0

    while choice != 6:

        print_menu()

        choice = getChoice(1, 6, "Enter a menu option: ")

        if choice == 1:   

            print_pokedex(pokedex)

        elif choice == 2:

            name = input("Enter a Pokemon name: ")

            name = name.capitalize()

            lookup_by_name(pokedex, name)

        elif choice == 3:

            number = getChoice(1, 1000, "Enter a Pokemon number: ")

            lookup_by_number(pokedex, number)

        elif choice == 4:

            type = input("Enter a Type: ")

            total_by_type(pokedex, type.lower())

        elif choice == 5:

            average_hit_points(pokedex)

    print("Thank you. Goodbye!")

# -----------------------------

main()

Output:



Related Solutions

the assignment folder for this assignment contains a file called values.txt. The first line in the...
the assignment folder for this assignment contains a file called values.txt. The first line in the file contains the total number of integers which comes after it. The length of this file will be the first line plus one lines long. Implement a MinHeap. Your program should read in input from a file, add each value to the MinHeap, then after all items are added, those values are removed from the MinHeap. Create a java class called MinHeap with the...
C++ There is a file, called EmployeeInfo.txt, that contains information about company employees work for a...
C++ There is a file, called EmployeeInfo.txt, that contains information about company employees work for a week. You will write a program that reads the info from the file, and produces an output file called EmployeePay.txt with information about the employees pay amount for that week. Details: The input file is called EmployeeInfo.txt There are 4 lines of input Each line has the same form Last Name, first Name, hours worked, pay rate, tax percentage, extra deductions Example: John Doe...
. The file contains information about baseball players in a fictitious league. Here is a sample...
. The file contains information about baseball players in a fictitious league. Here is a sample of the data: Janet Littleton,6,7,14 Frank Edbrooke,17,9,31 Robert Hovery,25,1,18 Thomas Bingham,21,8,2 Stephen Bruce,7,9,23 For each player it shows: Her name, How many doubles she hit, How many triples she hit, How many home runs she hit [End of Line] For example, Janet Littleton hit 6 doubles, 7 triples and 14 home runs. Frank Edbrooke hit 17 doubles, 9 triples and 31 home runs. Your...
In auditing the accounting payable cycle, the vulnerability will mostly come from failure to record and...
In auditing the accounting payable cycle, the vulnerability will mostly come from failure to record and report some liabilities. How will the auditor go about auditing for unrecorded liabilities? -Discuss
Partial information from the comparative balance sheet of Jackson Company as of December 31, 2020 and...
Partial information from the comparative balance sheet of Jackson Company as of December 31, 2020 and 2019 reflected the following selected account balances. From the information contained on the balance sheet and the additional information below, prepare the Net Cash Flows from Operating activities to answer the following two questions.   Jackson Company Comparative Balance Sheet Partial Information                                                            2020                2019 Current Assets: Cash                                                $114,000         $100,000 Accounts receivable                           18,400             20,700 Inventory                                            62,200             59,600 Current Liabilities: Accounts payable                               29,300             26,600 Accrued liabilities                                9,700             10,100 Additional information: Net income                                                       69,000 Depreciation expense                                         8,000 Question: What...
Overriding the equals Method File Player.java contains a class that holds information about an athlete: name,...
Overriding the equals Method File Player.java contains a class that holds information about an athlete: name, team, and uniform number. File ComparePlayers.java contains a skeletal program that uses the Player class to read in information about two baseball players and determine whether or not they are the same player. Fill in the missing code in ComparePlayers so that it reads in two players and prints “Same player” if they are the same, “Different players” if they are different. Use the...
Suppose we have an input file that contains information about how many hours each employee of...
Suppose we have an input file that contains information about how many hours each employee of a company has worked. The file looks like the following (Employee's name, Hours): John 6.5 9.5 7.25 9 8.55 Oscar 12.5 13.5 14 16 18.75 Judith 7 7 7 ••• Construct a program that reads this file and calculates the total number of hours worked by each individual. Make sure that the program handles each specific exception that could occur.' python
assignment in C I have a file that contains a lot of lines with words separated...
assignment in C I have a file that contains a lot of lines with words separated by spaces ( also contains empty lines as well). I need to read this file line by line and put each word into 2d array. NOTE: i need to skip spaces as well as empty lines. also I need to count each word.
On Moodle, you will find a file labelled “Data for Question 4 Assignment 1”. It contains...
On Moodle, you will find a file labelled “Data for Question 4 Assignment 1”. It contains data on past students in this course. Under Midterm is information on whether past studentsgot an A grade (A−, A, A+) an F or D grade (D is a passing grade but most students need aC− for it to count towards their program) or Other (any grade in between). Under FinalExam is information on whether students got a D or F grade or anything...
Start with the partial model in the file Ch03 P15 Build a Model.xls from the textbook’s...
Start with the partial model in the file Ch03 P15 Build a Model.xls from the textbook’s Web site. Joshua & White (J&W) Technologies’s financial statements are also shown below. Answer the following questions. (Note: Industry average ratios are provided in Ch03 P15 Build a Model.xls.) a. Has J&W’s liquidity position improved or worsened? Explain. b. Has J&W’s ability to manage its assets improved or worsened? Explain. c. How has J&W’s profitability changed during the last year? d. Perform an extended...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT