Application#

How to Submit#

Your answers to this chapter’s application questions should be added to the notebook template.

Submit the Colab link on Canvas for the assignment submission.

Application Questions#

Q1: Write a program that converts integer, float, or boolean values to a string, using the str() function.

Q2: Write a program that prompts the user to enter a 6-letter word, and then prints the first, third, and fifth letters of that word.

Q3: Modify the program provided below to search for the character q or u in the string. Does it always return the index number you expect? What index is returned if you ask for the index of the letter u (i.e., what happens when the desired character appears more than once in the string)?

Q4: Write a program that creates a list of numbers. Use the arguments and syntax presented in this section of the chapter to include code in your program that answers the following questions:

  • What is the length of your list?

  • What is the number position for each of the items in your list?

  • How would you return the value of the first item?

  • How would you return the value of the last item?

Answer to this question includes program + comments that document process and explain your code.

Q5: Modify your Q4 program (working with the same list), using arguments and syntax covered in this section of the chapter to accomplish the following tasks:

  • Add a new item to your list

  • Delete an item from your list

  • Sort your list in-place

  • Generate a sorted version of your list

  • Reverse your list in-place

  • Determine the min and max values for your list

Answer to this question includes program + comments that document process and explain your code.

Q6: Write a program that creates a dictionary on a topic of your choosing. Include at least 5 key-value pairs. Use arguments and syntax covered in this section of the chapter to accomplish the following tasks:

  • Add a new element to your dictionary

  • Update or modify an element in your dictionary

  • Print a list of all the keys in your dictionary

  • Print a list of all the values in your dictionary

Answer to this question includes program + comments that document process and explain your code.

Q7: Describe the five data structures covered in this chapter (strings, lists, dictionaries, tuples, sets) in your own words. How are they similar? What are key differences? What kinds of tasks/contexts/problems would benefit from specific structures?

  • NOTE: You are welcome to include code as part of this answer, but a code component is not required.

For these last two questions, you can use any of the data structures and arguments/syntax presented in this lab. As part of your answer, include a brief explanation for why you choose a particular data structure for the task.#

Q8: Write a program that asks a user to input their current or former Notre Dame residence hall and returns or outputs that hall’s mascot (link to table with list of halls and mascots).

Sample output for this program:

Howard Hall's mascot is ducks!

Answer to this question includes program + comments that document process and explain your code, as well as a brief explanation for the data structure/approach you chose for this program.

Q9: In a previous chapter, you wrote a program that asks the user to enter a color value and returns an output message indicating whether the color is a primary, secondary, or tertiary color (using a combination of the input() function, comparison operators, if-then-else logic, and Boolean logical operators).

Primary colors:

  • Red

  • Yellow

  • Blue

Secondary colors:

  • Green

  • Orange

  • Purple

Tertiary colors:

  • Amber

  • Vermillion

  • Magenta

  • Violet

  • Teal

  • Chartreuse

Let’s revisit and rewrite this program- how could you approach this task using the data structures and syntax presented in this lab?

Answer to this question includes program + comments that document process and explain your code, as well as a brief explanation for the data structure/approach you chose for this program.