Question

BlockPy: #43.1) Dictionaries vs. Tuples Create a dictionary to store the dimensions for a box. Then, create a tuple to store

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

dimension_dict={'Length':6,'Width':8,'Height':4} #creating dictionary with dimensions
dimension_tuple=(6,8,4) #creating tuple with dimensions
print("Accessing Length Using Dictionaries is " ,dimension_dict['Length']) #access dictionary value using key
print("Accessing Length Using tuples is " , dimension_tuple[0],end="\n\n") #accees tuple value using index

print("Accessing Width Using Dictionaries is " , dimension_dict['Width']) #accessing width key in dictionary
print("Accessing Width Using tuples is " , dimension_tuple[1],end="\n\n") #accessing first index element in tuple


print("Accessing Height Using Dictionaries is " , dimension_dict['Height']) #printed in detail way
print("Accessing Height Using tuples is " , dimension_tuple[2])

Code and Output Screenshots:

1 dimension_dict={Length:6, Width:8,Height:4} #creating dictionary with dimensions 2 dimension_tuple-(6,8,4) #creating

Note : For accessing the value in dictionaries we will access with key field where as in tuple for accessing any element we will use index.By default the starting index is 0 that means if we access any tuple with index 0 it will give first element of a tuple. In code printed each dimension value by accessing dictionary and tuple and explained each statement in detailed way.

Note : if you have any queries please post a comment..thanks a lot..always available to help you..

Add a comment
Know the answer?
Add Answer to:
BlockPy: #43.1) Dictionaries vs. Tuples Create a dictionary to store the dimensions for a box. Then,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Questions 1. How to create a comment in python? 2. The way to obtain user input...

    Questions 1. How to create a comment in python? 2. The way to obtain user input from command line 3. List standard mathematical operators in python and explain them 4. List comparison operators in python 5. Explain while loop. Give example 6. Explain for loop. Give example 7. How to create infinite loop? And how to stop it? 8. Explain a built-in function ‘range’ for ‘for’ loop 9. Explain break statement 10. Explain continue statement 11. Explain pass statement 12....

  • IN C# Objectives: Create an application that uses a dictionary collection to store information ...

    IN C# Objectives: Create an application that uses a dictionary collection to store information about an object. Understanding of abstract classes and how to use them Utilize override with an abstract class Understanding of Interfaces and how to use them Implement an Interface to create a “contract” between classes. Compare and contrast inheritance and interfaces. Instructions: Interface: Create an interface called ITrainable which contains the following: Dictionary<string, string> Behaviors{ get; set; } string Perform(String signal); string Train(String signal, string behavior);...

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

  • C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for...

    C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions: Shipping requirements The package weight must not exceed 50 pounds. The package must not exceed 3 feet in length, width, or height. The girth of the package must not exceed 5 feet. The girth is the circumference around the two smallest sides of the package. If side1, side2, and side3 are the lengths of the three sides, and...

  • please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you! In this homework, you...

    please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you! In this homework, you are going to write a program to represent various types of packages offered by package-delivery services. You need to create an inheritance hierarchy to represent various types of packages with different shipping options and associated costs. The base class is Package and the derived classes are FlatRatePackage and OvernightPackage. The base class Package includes the following attributes: • Sender information: senderName (string), senderAddress (string),...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT