Question

In: Computer Science

1. Use the get() method to print the value of the "name" key and the value...

1. Use the get() method to print the value of the "name" key and the value of the "age" key of the stuInfo dictionary.
Use the variable given below:
stuInfo = {'name': 'John Smith', "gpa": 3.456, "age": 20}

2. Use the dict() function to make a copy of the NY dictionary to NewYorkState dictionary.

3. Change the "name" value from "John Smith" to "James Bond" of the stuInfo dictionary.
Use the variable given below:
stuInfo = {'name': 'John Smith', "gpa": 3.456, "age": 20}

need help with Python. Please help ASAP. Please please please.

Solutions

Expert Solution

Question 1

get() method is used to return value of an item of given key.

Syntax : dictionaryname.get(keyname)

Here, dictionary name is stuInfo.

To get value of age key, we can write

stuInfo.get("name")

If you want to print it, then write print(stuInfo.get("name"))

It will print John Smith

Same for age key, stuInfo.get("age") will return 20.

If you want to print it, then write print(stuInfo.get("age"))

It will print 20

Question 2

To copy NY directory to NewYorkState directory using dict() function

NewYorkState = dict(NY)

Question 3

To change value of name key from "John Smith" to "James Bond" of the stuInfo dictionary

stuInfo["name"] = 'James Bond'

Below is code reference,

#Question 1

#given dictionary
stuInfo = {'name': 'John Smith', "gpa": 3.456, "age": 20}

#get method to print value of "name" key
print(stuInfo.get("name"))

#get method to print value of "age" key
print(stuInfo.get("age"))

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

#Qusetion 2

#NY dictionary
NY = {
  "name": "New York",
  "country": "US"
}

#to copy NY to NewYorkState dictionary
NewYorkState = dict(NY)

#to print NewYorkState
print(NewYorkState)

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

#Qustion 3

#given directory
stuInfo = {'name': 'John Smith', "gpa": 3.456, "age": 20}

#it will change the value of name key
stuInfo["name"] = 'James Bond'

#print new stuInfo directory
print(stuInfo)

You can refer below code screenshot to understand output also.


Related Solutions

On Python a) Use format() method to print an integer value entered by the user and...
On Python a) Use format() method to print an integer value entered by the user and its cube root with two decimal places. b) Print the same values as part (a) using format() function with keyword arguments and labels number and cubeRoot as in: format(number=n,cubeRoot=cr) c) Switch the order of keyword arguments and show that this has no effect on the output.
Euler’s Method Let’s get our hands dirty and actually use Euler’s method to estimate the value...
Euler’s Method Let’s get our hands dirty and actually use Euler’s method to estimate the value of y(2) where y is the solution to the initial value problem y′=y−2x             y(0) = 1 Recall that Euler’s method says: Approximate values for the solution of the initial value problem y′=F(x, y),y(x0) =y0 with step size h, at xn=xn−1+h, are yn=yn−1+hF(xn−1, yn−1) Fill in the table for steps of size h= 0.2. n xn yn=yn-1+0.2F(xn-1,Yn-1 y'=F(xn,yn) 0 0 1 1 .2 2 .4...
PLEASE USE MEHODES (Print part of the string) Write a method with the following header that...
PLEASE USE MEHODES (Print part of the string) Write a method with the following header that returns a partial string: public static String getPartOfString(int n, String firstOrLast, String inWord) Write a test program that uses this method to display the first or last number of characters of a string provided by the user. The program should output an error if the number requested is larger than the string. SAMPLE RUN #1: java PartOfString Enter a string: abracadabra↵ Enter the number...
3. [Method 1] In the Main class, write a static void method to print the following...
3. [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. 4. [Method 2] In the...
1. What is the name of the method we use to find optimal solutions when given...
1. What is the name of the method we use to find optimal solutions when given a function and at least one constraint? 2. Give a real-life example of an optimization problem in your academic discipline (a function of several variables with constraints). 3. Write a paragraph about the importance of this topic in science, technology, engineering, and mathematics (STEM) research.
Use LinkedList build-in class (java.util.LinkedList) to write a Java program that has: A. Method to print...
Use LinkedList build-in class (java.util.LinkedList) to write a Java program that has: A. Method to print all elements of a linked list in order. B. Method to print all elements of a linked list in reverse order. C. Method to print all elements of a linked list in order starting from specific position. D. Method to join two linked lists into the first list in the parameters. E. Method to clone a linked list. The copy list has to be...
1) Use either the critical value or p-value method for testing hypotheses. 2) Identify the null...
1) Use either the critical value or p-value method for testing hypotheses. 2) Identify the null and alternative hypotheses, test statistic, P-value (or range of P-values), and critical value(s). 3) State your final conclusion that addresses the original claim. Include a confidence interval as well and restate this in your original conclusion. In a random sample of 300 patients, 21 experienced nausea. A drug manufacturer claims that fewer than 10% of patients who take its new drug for treating Alzheimer’s...
Use the discounted payback method, the net present value method, and the profitability index method to...
Use the discounted payback method, the net present value method, and the profitability index method to evaluate the following project: Year 0 Initial Investment 900,000 Year 1 Income 175,000 Year 2 Income 450,000 Year 3 Additional investment 100,000 Year 4 Income 630,000 Discount rate 7% DPB __________ years NPV ______________ PI ______________ Would you recommend that the board accept or reject this project? ________________ Accept or reject
Name the three key epigenetic modifications, and name a few key physiological,cellular etc. processes they are...
Name the three key epigenetic modifications, and name a few key physiological,cellular etc. processes they are important in:
QUESTION #1 – What is the controversy surrounding use of the intrinsic value method? QUESTION #2...
QUESTION #1 – What is the controversy surrounding use of the intrinsic value method? QUESTION #2 – Describe what is the treasury stock method. When is it used? QUESTION #3 – IN YOUR OWN WORDS, what does earnings per share mean? IN YOUR OWN WORDS. QUESTION #4 – How can the issuance of stock options affect EPS? QUESTION #5 – How do we measure compensation expense for stock options?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT