Question

In: Computer Science

Exercise: Change Orb Location ------------------------- ### Description In this series of exercises, you will create functions...

Exercise: Change Orb Location
-------------------------

### Description

In this series of exercises, you will create functions
to create, modify and examine dictionaries that
represent information about a memory orb. Memory
orbs have three important pieces of information:
The `emotion` that created the memory, the `location`
the memory is stored, and the `data` which is the
information in the memory.

For this exercise, you will create a function that
will change the value of the `location` key in a
dictionary.

### Files

* `orbfunctions.py` : set of functions to work with memory orbs.

### Function Name

`move_orb`

### Parameters

* `orb` : a dictionary
* `new_location` : a string, the new value for `location`

### Action

Changes the value associated with the key `location`.

### Return Value

The modified dictionary, `orb`.

def create_orb(emotion, location, data):
dict = {
"emotion":emotion,
"location":location,
"data":data
}
return dict

def orb_get_emotion(orb):
return orb["emotion"]

def change_orb_emotion(orb, new_emotion):
orb.update({"emotion":new_emotion})
return orb
def orb_get_location(orb):
if orb.get('location'):
return orb.get('location')
else:
return None
  
def move_orb(orb,location):
if

Solutions

Expert Solution

'''Functions to create ,modify and examine dictionaries'''

#create dictionary named orb with value and key provided
def create_orb(emotion,location,data):
  orb = {
  #set the values from the parameter
  'emotion':emotion, 
  'location':location,
  'data':data
  }
  return orb #return the dictionary orb

#Set memory location 
def mov_orb(orb,new_location):
  orb['location'] = new_location #To set the location
  return orb #return the modified dictionary orb

#Get memory location
def orb_get_location(orb):
  return orb.get('location') #Return the memory location of key location

#Set emotion 
def change_orb_emotion(orb,new_emotion):
  orb['emotion']=new_emotion #Set the emotion of memory
  return orb #Return modified dictionary orb

#Get the emotion
def orb_get_emotion(orb):
  return orb.get('emotion') #Return the emotion of memory

'''Include the data methods of set and get.Additionally'''

#Set data in memory 
def change_orb_data(orb,new_data):
  orb['data']=new_data #Set the value
  return orb #Return the modified value

#Get the data which is the information in the memory
def orb_get_data(orb):
  return orb.get('data') #return the data


'''To test the code'''
#Create an orb dictionary with random values
orb_created = create_orb("temperature low","flash","Computer memories")
print("Orb Dictionary \n ", orb_created) #Printed the Orb dictionary
modified_location_orb= mov_orb(orb_created,"RAM") #Call function mov_orb() to change location
print("Location Modified Orb \n",modified_location_orb) 
newlocation = orb_get_location(modified_location_orb) #Function to return orb location
print("Newlocation\n",newlocation)
modified_emotion_orb = change_orb_emotion(modified_location_orb,"temperature rise") #Call change_orb_emotion to change emotion
print("Emotion Modified Orb \n",modified_emotion_orb)
newemotion = orb_get_emotion(modified_emotion_orb) #Function to return emotion
print("NewEmotion \n:",newemotion)

'''Included change and get data function additionally'''
modified_data_orb = change_orb_data(modified_emotion_orb,"Pictures") #Call function change_orb_data() to change data
print("Data Modified Orb\n",modified_data_orb)
newdata= orb_get_data(modified_data_orb) #Function to get orb data
print("NewData\n",newdata)

Summary:

Function to create, modidy and examine dictionary orb.

Step: Create dictionary with provided parameters emotion,location and data.

Step2: Set and Get the location in orb dictionary

1) To set the location use the subscript notation dictionary[key] = value

2) To get the location use get() method as if the key not found if return None without any errors

Step 3: Repeat the above step for both emotion and data

Step 4: The set methods return the modified dictionary orb whereas the get methods return the parameter changed.  

Additonally to the asked quest i have include the change_orb_data() and orb_get_data() for your reference.


Related Solutions

Exercise: Add Monster Cast Member ------------------------- ### Description In this series of exercises, you will create...
Exercise: Add Monster Cast Member ------------------------- ### Description In this series of exercises, you will create functions to create, modify and examine dictionaries that represent characters in an animated film, and the cast members who voice the characters. The keys of the dictionary will be character names. The values in the dictionary will be voice actor names. For this exercise, you will create a function that adds an entry to a dictionary. They key is a character name, and the...
In Java...create a class Realestate.java with the following fields: location, price, and description. Create a class...
In Java...create a class Realestate.java with the following fields: location, price, and description. Create a class RealestateFinder.java that reads in real estate data from a CSV file (RealestateList.csv). Then provide the user with the following options: Sort per Price, Sort per Location, and Exit. Use ArrayList and Arrays.sort to perform the sorts and display the data to the user.
PYTHON Exercise: Accelerate Method ------------------------- ### Description In this exercise, you will add to your `Car`...
PYTHON Exercise: Accelerate Method ------------------------- ### Description In this exercise, you will add to your `Car` class a method to accelerate the speed of an instance. ### Class Name `Car` ### Method `accelerate()` ### Parameters * `self` : the `Car` object to use * `delta_speed` : a number, the desired value to add to the speed data member. ### Action Adds `delta_speed` to the speed of the object. If the new speed is too fast, then set the speed to...
what are the different muscular tissues their functions and location
what are the different muscular tissues their functions and location
Provide a description of our home galaxy, the Milky Way. Include in your description the location...
Provide a description of our home galaxy, the Milky Way. Include in your description the location and stellar populations (new stars/ old stars) of the central bulge, disk, and halo. Also provide details such as the Hubble classification, disk structure, location of star forming regions, and the best estimate of the number of spiral arms.
For a double slit experiment, would the location of the central maximum change if you move...
For a double slit experiment, would the location of the central maximum change if you move the light source (originally at the center line) directly behind one of the slits? if so, would it move up or down?
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' //...
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' // This variable should be assigned a new object // In this object create three key:value pairs // The keys should be: 'name', 'city', 'favoriteAnimal' // The values should be strings associated with the keys. // return the variable 'aboutMe' } function exerciseTwo(animal){ // Exercise Two: In this exercise you will be given an object called 'animal' // Create a new variable called 'animalName' //...
The Problem Below are a series of problems you need to solve using recursive functions. You...
The Problem Below are a series of problems you need to solve using recursive functions. You will write a program that will read commands from an input file, with each command referring to one of the recursive problems to be executed. Each command will be followed (on the same line of input) by the respective parameters required for that problem. Implementation Each recursive function MUST have a wrapper function enclosing it where you will do input/output file processing as well...
Provide a brief description of 7 plus Seven series and the main character of the series.
Provide a brief description of 7 plus Seven series and the main character of the series.
In this exercise, the first of a series, we will make connections between the physics you...
In this exercise, the first of a series, we will make connections between the physics you have been learning (in this case, kinematics) and how it is used by people in their work and research. Today we consider an example from kinesiology research, based on a 2000 paper from the Journal of Measurement in Physical Education and Exercise Science (nota bene: you do not have to read this paper, or any of the hyperlinks to follow the exercise – it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT