Week 9 Discussion
.docx
keyboard_arrow_up
School
University of Maryland Global Campus (UMGC) *
*We aren’t endorsed by this school
Course
617
Subject
Computer Science
Date
Apr 3, 2024
Type
docx
Pages
2
Uploaded by DeanGullMaster970
Contains unread posts
What is meant by a dictionary in Python? And why are they useful?
A Dictionary can be described as an object that stores a collection of data.
Dictionaries are useful because it can be used to retrieve a specific value by using the key associated with it.
After reading chapter 8 of the text book, and checking out the lecture notes, do the following exercise:
Write a program that asks a user for a gene ID or accession number and returns the sequence that corresponds to that gene. Use a dictionary to accomplish this. Get the genes and their sequences from NCBI and create the dictionary so that the key = gene ID and value = sequence. Handle the
case where the gene ID is not found in the dictionary.
# Create dictionary of gene sequences
gene_sequences = {
"BRCA1": "GTGATCCGCTCACCTTGACCTCCCAAAGTGCTGGGATTAAAGGCA
TGAGCCACTGTGCCCCGCCAGGAAA",
"BRCA2": "GTGGCGCGAGCTTCTGAAACTAGGCGGCAGAGGCGGAGCCGCT
GTGGCACTGCTGCGCCTCTGCTGCGCC",
"CDKN2B-AS1": "AGCTACATCCGTCACCTGACACGGCCCTACCAGGAACAGCCGCG
CTCCCGCGGATTCTGGTGCTGCTCGC",
"MLH1": "GAAGAGACCCAGCAACCCACAGAGTTGAGAAATTTGACTGGCATT
CAAGCTGTCCAATCAATAGCTGCCG",
"CCAT2": "CCGAGGTGATCAGGTGGACTTTCCTGGATGTTCTGGGTCTTGACC
TGATTGCTGAAAAATGAATACAAAT",
"PRNCR1": "AAATCTCAGCCTCCCACTCCCATATTTACAGTTTGATTAGGGAGG
CACATTTAGATATGCAGTGATAATT",
}
# Function to search for a gene sequence based on gene ID
def find_gene_sequence(gene_id):
if gene_id in gene_sequences:
return gene_sequences[gene_id]
else:
return "Gene ID not found"
# Main program loop
while True:
user_input = input("Enter a gene ID or accession number (type 'stop' to exit): ")
if user_input.lower() == "stop":
print("Stopped program.")
break
sequence = find_gene_sequence(user_input)
print(f"Sequence for {user_input}: {sequence}")
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
3- Given a dictionary my_dict= {‘a’:1,’b’:2,’c’:3,’d’:4,’e’:5,’f’:6,’g’:7,’h’:8,’I’:9,’j’:10} Write a python program that prints the keys where the value stored is a prime number
arrow_forward
Program: Python
Create a free choice game using a PYTHON DICTIONARY
Make the game original yet simple, the main point is to access and manipulate a Python Dictionary the game doesn't have to be complicated but simple just for an understanding of how python dictionary works.
arrow_forward
Python Programming
arrow_forward
python programming
arrow_forward
In Python
NO IMPORT PICKLE
Please check pictures and fix code.
Write a program that keeps names and email addresses in a dictionary as key-value pairs.
This is the Required Output example:
Menu
----------------------------------------
1. Look up an email address
2. Add a new name and email address
3. Change an existing email address
4. Delete a name and email address
5. Quit the program
Enter your choice: 2
Enter name: John
Enter email address: John@yahoo.com
That name already exists
Menu
----------------------------------------
1. Look up an email address
2. Add a new name and email address
3. Change an existing email address
4. Delete a name and email address
5. Quit the program
Enter your choice: 2
Enter name: Jack
Enter email address: Jack@yahoo.com
Name and address have been added
Menu
----------------------------------------
1. Look up an email address
2. Add a new name and email address
3. Change an existing email address
4. Delete a name and email address
5.…
arrow_forward
need help with python...paste indented code here...
QUESTION 6
Implement the following:
a) Create a dictionary, grades, and initialize it with the following data:'Jimmy': 66 'Jerry': 80'Jacob': 71'James': 59'Jenny': 90
b) Use a loop to print all items of the dictionary grades as follows:name receives grade A (if the value is 90 or above).name receives grade B (if the value is 80 or above).name receives grade C (if the value is 70 or above).name receives grade D (if the value is 60 or above).name receives grade F (if the value is below 60).
Example OutputJimmy receives grade D.Jerry receives grade B.Jacob receives grade C.James receives grade F.Jenny receives grade A.
arrow_forward
Need help with this PLEASE
Create a dictionary with at-least 5 entries with name as key and phone number as its value. Both are string. The phone number should be in the format XXX-XXX-XXXX.
Write a menu-driven program with the following menu options:
a. Lookup up a phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, print the phone number.
b. Update a Phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, ask the user to input the updated phone number and display your updated dictionary.
c. Delete a phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, delete the entry and display the dictionary after deletion.
HERES CODE DOESNT WORK:
a = {"A":"123-456-7890" , "B":"098-765-4321","C":"134-987-4532",…
arrow_forward
Need help with this PLEASE
Create a dictionary with at-least 5 entries with name as key and phone number as its value. Both are string. The phone number should be in the format XXX-XXX-XXXX.
Write a menu-driven program with the following menu options:
a. Lookup up a phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, print the phone number.
b. Update a Phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, ask the user to input the updated phone number and display your updated dictionary.
c. Delete a phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, delete the entry and display the dictionary after deletion.
arrow_forward
Question 1
Write a Python program which will take N names from the user. Create a
dictionary from the N names that will hold First_name, Middle_name and
Last_name in separate keys. The inputs will take N at first and then take N
names. You can assume that the names will contain less than or equal 3
words and there will be single space between each part of the name.
Sample Input:
4.
Zubayer Ahmed
Sadia Nur Amin
Mehedi Hasan Shawon
Nafis
Sample Output: { "Fname" : ["Zubayer", "Sadia", “Mehedi", “Nafis"],
"Mname" : ["Nur", "Hasan"], "Lname" : ["Ahmed", “Amin", “Shawon"] }
arrow_forward
Python
I have a text file I need to input that has all the States and their capitals laid out like this.
New York
Albany
Georgia
Atlanta
Then I need to put them into a dictionary using a while loop. I'm having trouble figuring out how to make the state a key and the capital a value in the dictionary.
This is the request from the proffessor.
Remember the state name is on one line, and the capital is on the following line, so it makes sense to read the file using a while loop. The file reader steps look like this.
Define & initialize your variables
Open the file
Read the first line to get a state
While the state is not EOF
Read the following line to get capital
Strip off the EOL characters
Stuff capital into a dictionary using the state as key
Read next state
Close the file
Return the dictionary variable
arrow_forward
Dictionary & Tuple
1. Write a Python program to combine two dictionaries into one by adding values for
common keys. Input contains two comma separated dictionaries. Print the new
dictionary and create a tuple which contains unique values in sorted order.
Sample Input
а: 100, b: 100, с: 200, d: 300
а: 300, b: 200, d: 400, e: 200
Sample Output
{'a': 400, 'b': 300, 'c': 200,'d': 700, 'e': 200}
Values: (200, 300, 400, 700)
6.
2. Write a python program which prints the frequency of the numbers that were
given as input by the user. Stop taking input when you find the string "STOP". Do
not print the frequency of numbers that were not given as input. Use a dictionary
to solve the problem
Sample Input
Sample Output
10 - 2 times
10
20
20 - 2 times
20
30 - 1 times
50 - 1 times
90 - 1 times
30
10
50
90
STOP
arrow_forward
Please code in python
Forbidden concepts: recursion, custom classes
Create a program that takes a university student’s name, their 1st parent’s income, and their second parent’s income. If the average income between the parents is $40,000 or below, then it would put them into a Tuition Grant list. If it’s above, then it would be a Full Tuition Required list. Once the university admission officer has completed inputting all the students, the program will end and print out the two lists.
arrow_forward
Python. Please comment out each step.
arrow_forward
This is a python File
Create a program that presents a menu with these options:
Add product
Sort by quantity (low to high)
Print Inventory
Quit
Read the initial product information from a text file.
Remember to ask the user to enter the filename & make sure it exists! The program should NOT product an error if the file isn’t there!
Store the product information into a DICTIONARY called prodDict. The dictionary should map the productID (the key for the dictionary) to a LIST that contains description, unitPrice, and quantity.
The text file will be structured as shown below, where each line contains the product id, product description, unitPrice and quantity.NOTE: Each entry on the line is separated by a comma and a space.
Example textfile:
111, arm chair, 99.99, 5444, desk, 10, 40777, lamp, 20, 5333, credenza, 50.98., 20222,bassinet , 5.59, 10
Example of the empDict after the information shown has been readd and stored:{ 111: [“George Gray”, 10, 40], 222: [“Amy Abrahmson”,…
arrow_forward
Simple login system
PYTHON
Create a static dictionary with a number of users and with the following values:
First name
Last name
Email address
Password
Ask the user for:
5. Email address 6. Password
Loop (for()) through the dictionary and if (if()) the user is found print the following:
7. Hello, first name last name you have successfully logged in 8. Notify the user if the password and email address are wrong 9. Additional challenge: if you want the program to keep asking for a username and password when the combination is wrong, you will need a while() loop.
arrow_forward
Python
arrow_forward
Code the following directions in python:
1.Write a statement that creates a dictionary containing the following key-value pairs:
'a' : 1
'b' : 2
'c' : 3
2.Write a statement that creates an empty dictionary.
3.Assume the variable dct references a dictionary. Write an if statement that determines whether the key 'James' exists in the dictionary. If so, display the value that is associated with that key. If the key is not in the dictionary, display a message indicating so.
arrow_forward
kindly answer the following:
arrow_forward
Date: 26th April 2021
Course: BIT1054 Fundamental of Computational Thinking:
Python
d) Write a Python program that stores information below in a dictionary. Then, update the
age to 19 years old and add another entry named 'College' with value 'City University'.
Print out the age and college.
Name:
Lee Chong Wei
Age:
20
Course:
Computer Science
[5 marks]
Answer:
arrow_forward
Python Language - Robot Location
arrow_forward
CodeWorkout
Gym
Course
Q Search
kola shreya@ columbusstate.edu
Search exercises...
X274: Recursion Programming Exercise: Cannonballs
X274: Recursion Programming Exercise:
Cannonballs
Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top,
sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine.
cannonballs, and so forth.
Given the following recursive function signature, write a recursive function that takes as its argument the
height of a pyramid of cannonballs and returns the number of cannonballs it contains.
Examples:
cannonball(2) -> 5
Your Answwer:
1 public int cannonball(int height) {
3.
4}
Check my answer!
Reset
Next exercise
Feedback
arrow_forward
python exercise:
Write a Python function called get_top_students that takes the list of dictionaries as input and returns a dictionary containing the name and GPA of the top two students in the list. Each dictionary has the following keys: "name", "age", "major", and "gpa".
arrow_forward
Complete the following statements about a Python dictionary.
Strings
be used as keys of a Python dictionary.
Floats
be used as keys of a Python dictionary.
be used as keys of a Python dictionary.
Lists
Dictionaries
can
cannot
be used as keys of a Python dictionary.
arrow_forward
Python
The program will create a quiz that will ask for the capital of a random state. Your program will repeat so that a total of 5 random states are presented to the user
Write a program that creates a dictionary containing the U.S. states as keys, and their capitals asvalues. (Use the Internet to get a list of the states and their capitals.) The program should then randomly quiz the user by displaying the name of a state and asking the user to enter that state’s capital. The program should keep a count of the number of correct and incorrect responses. (As an alternative to the U.S. states, the program can use the names of countries and their capitals.)
arrow_forward
Using the Python language answer the following questions below. Please tell me what program you use if it is IDLE or Atom or a python website please provide the website you use.
arrow_forward
4- Given a dictionary: capitals= {'CHINA': 'BEIJING','CUBA': 'HAVANA', 'USA': 'WASHINGTON, D.C.'} Write a python program to print keys and values in new line. Example output:
CHINA
BEIJING
CUBA
.
.
.
arrow_forward
How do I do this using python
arrow_forward
C++ Progrmaing
Instructions
Redo Programming Exercise 6 of Chapter 8 using dynamic arrays. The instructions have been posted for your convenience.
The history teacher at your school needs help in grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains answers to the test in the form:
TFFTFFTTTTFFTFTFTFTT
Every other entry in the file is the student ID, followed by a blank, followed by the student’s responses. For example, the entry:
ABC54301 TFTFTFTT TFTFTFFTTFT
indicates that the student ID is ABC54301 and the answer to question 1 is True, the answer to question 2 is False, and so on. This student did not answer question 9 (note the empty space). The exam has 20 questions, and the class has more than 150 students. Each correct answer is awarded two points, each wrong answer gets one point deducted, and no answer gets zero points. Write a program that processes the test data. The output should be the student’s ID,…
arrow_forward
create a code in Python asking a user to enter data for the dictionary until user has stop the program to stop entering data
use variables customer for name and pay for pay in float
arrow_forward
Answer the following below please. M
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Related Questions
- 3- Given a dictionary my_dict= {‘a’:1,’b’:2,’c’:3,’d’:4,’e’:5,’f’:6,’g’:7,’h’:8,’I’:9,’j’:10} Write a python program that prints the keys where the value stored is a prime numberarrow_forwardProgram: Python Create a free choice game using a PYTHON DICTIONARY Make the game original yet simple, the main point is to access and manipulate a Python Dictionary the game doesn't have to be complicated but simple just for an understanding of how python dictionary works.arrow_forwardPython Programmingarrow_forward
- python programmingarrow_forwardIn Python NO IMPORT PICKLE Please check pictures and fix code. Write a program that keeps names and email addresses in a dictionary as key-value pairs. This is the Required Output example: Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program Enter your choice: 2 Enter name: John Enter email address: John@yahoo.com That name already exists Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5. Quit the program Enter your choice: 2 Enter name: Jack Enter email address: Jack@yahoo.com Name and address have been added Menu ---------------------------------------- 1. Look up an email address 2. Add a new name and email address 3. Change an existing email address 4. Delete a name and email address 5.…arrow_forwardneed help with python...paste indented code here... QUESTION 6 Implement the following: a) Create a dictionary, grades, and initialize it with the following data:'Jimmy': 66 'Jerry': 80'Jacob': 71'James': 59'Jenny': 90 b) Use a loop to print all items of the dictionary grades as follows:name receives grade A (if the value is 90 or above).name receives grade B (if the value is 80 or above).name receives grade C (if the value is 70 or above).name receives grade D (if the value is 60 or above).name receives grade F (if the value is below 60). Example OutputJimmy receives grade D.Jerry receives grade B.Jacob receives grade C.James receives grade F.Jenny receives grade A.arrow_forward
- Need help with this PLEASE Create a dictionary with at-least 5 entries with name as key and phone number as its value. Both are string. The phone number should be in the format XXX-XXX-XXXX. Write a menu-driven program with the following menu options: a. Lookup up a phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, print the phone number. b. Update a Phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, ask the user to input the updated phone number and display your updated dictionary. c. Delete a phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, delete the entry and display the dictionary after deletion. HERES CODE DOESNT WORK: a = {"A":"123-456-7890" , "B":"098-765-4321","C":"134-987-4532",…arrow_forwardNeed help with this PLEASE Create a dictionary with at-least 5 entries with name as key and phone number as its value. Both are string. The phone number should be in the format XXX-XXX-XXXX. Write a menu-driven program with the following menu options: a. Lookup up a phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, print the phone number. b. Update a Phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, ask the user to input the updated phone number and display your updated dictionary. c. Delete a phone number based on name. Ask the user to input a name, if the name is not present in the dictionary, print an error message. Otherwise, delete the entry and display the dictionary after deletion.arrow_forwardQuestion 1 Write a Python program which will take N names from the user. Create a dictionary from the N names that will hold First_name, Middle_name and Last_name in separate keys. The inputs will take N at first and then take N names. You can assume that the names will contain less than or equal 3 words and there will be single space between each part of the name. Sample Input: 4. Zubayer Ahmed Sadia Nur Amin Mehedi Hasan Shawon Nafis Sample Output: { "Fname" : ["Zubayer", "Sadia", “Mehedi", “Nafis"], "Mname" : ["Nur", "Hasan"], "Lname" : ["Ahmed", “Amin", “Shawon"] }arrow_forward
- Python I have a text file I need to input that has all the States and their capitals laid out like this. New York Albany Georgia Atlanta Then I need to put them into a dictionary using a while loop. I'm having trouble figuring out how to make the state a key and the capital a value in the dictionary. This is the request from the proffessor. Remember the state name is on one line, and the capital is on the following line, so it makes sense to read the file using a while loop. The file reader steps look like this. Define & initialize your variables Open the file Read the first line to get a state While the state is not EOF Read the following line to get capital Strip off the EOL characters Stuff capital into a dictionary using the state as key Read next state Close the file Return the dictionary variablearrow_forwardDictionary & Tuple 1. Write a Python program to combine two dictionaries into one by adding values for common keys. Input contains two comma separated dictionaries. Print the new dictionary and create a tuple which contains unique values in sorted order. Sample Input а: 100, b: 100, с: 200, d: 300 а: 300, b: 200, d: 400, e: 200 Sample Output {'a': 400, 'b': 300, 'c': 200,'d': 700, 'e': 200} Values: (200, 300, 400, 700) 6. 2. Write a python program which prints the frequency of the numbers that were given as input by the user. Stop taking input when you find the string "STOP". Do not print the frequency of numbers that were not given as input. Use a dictionary to solve the problem Sample Input Sample Output 10 - 2 times 10 20 20 - 2 times 20 30 - 1 times 50 - 1 times 90 - 1 times 30 10 50 90 STOParrow_forwardPlease code in python Forbidden concepts: recursion, custom classes Create a program that takes a university student’s name, their 1st parent’s income, and their second parent’s income. If the average income between the parents is $40,000 or below, then it would put them into a Tuition Grant list. If it’s above, then it would be a Full Tuition Required list. Once the university admission officer has completed inputting all the students, the program will end and print out the two lists.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning