- 24th Jul 2024
- 18:40 pm
- Aditya Lakhera
For this assignment, you will write a program using a dictionary.: Write a program to prompt the user to enter a car model, manufacturer, average mpg and base sales price. Create a dictionary with the data. Output the dictionary. Then remove the mpg from the dictionary an output again. REMEMBER to put your name on the lab in comments, and comment throughout the program with what the program is doing.
Free Assignment Solution - Car Model Information Program: Using Dictionaries
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Solution.ipynb",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "code",
"source": [
"# propmt data from user\n",
"output_dict = {}\n",
"\n",
"\n",
"output_dict[\"model\"] = input(\"Please enter car model: \")\n",
"output_dict[\"manufacturer\"] =input(\"Please enter manufacturer: \")\n",
"output_dict[\"average_mpg\"] =input(\"Please enter average mpg: \")\n",
"output_dict[\"base_sales_price\"] =input(\"Please enter base sales price: \")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "kNC8b3QrHpfB",
"outputId": "12dd2633-8205-40a6-ec7b-8805e5f81c3b"
},
"execution_count": 7,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please enter car model: Truck\n",
"Please enter manufacturer: Tesla\n",
"Please enter average mpg: 21643\n",
"Please enter base sales price: 28364832\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Show created dictionary\n",
"output_dict"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "fGPXkAjuHpdD",
"outputId": "9ebc47e0-ba64-437f-e00a-518a7fdd5f76"
},
"execution_count": 8,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'average_mpg': '21643',\n",
" 'base_sales_price': '28364832',\n",
" 'manufacturer': 'Tesla',\n",
" 'model': 'Truck'}"
]
},
"metadata": {},
"execution_count": 8
}
]
},
{
"cell_type": "code",
"source": [
"#remove mpg from dictionary\n",
"del output_dict[\"average_mpg\"]"
],
"metadata": {
"id": "0To7owEYJ-wR"
},
"execution_count": 9,
"outputs": []
},
{
"cell_type": "code",
"source": [
"output_dict"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "n33g63FsKYOQ",
"outputId": "4dd9b30e-4fdd-40de-b0a0-bc46b24e403c"
},
"execution_count": 10,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"{'base_sales_price': '28364832', 'manufacturer': 'Tesla', 'model': 'Truck'}"
]
},
"metadata": {},
"execution_count": 10
}
]
},
{
"cell_type": "code",
"source": [
""
],
"metadata": {
"id": "PS512E7nKZlL"
},
"execution_count": null,
"outputs": []
}
]
}
Get the best Car Model Information Program: Using Dictionaries Assignment help and tutoring services from our experts now!
Please note that our Python programmers have completed this programming sample assignment. The solutions provided are meant for research and reference purposes only. If you find the reports and code helpful for learning concepts, our Python tutors would greatly appreciate it.
- For a complete solution package including code, reports, and screenshots, please visit our Python Assignment Sample Solution page.
- If you need assistance or clarification on this assignment, feel free to reach out to our Python tutors for personalized online tutoring sessions.
- You can also find a partial solution to this assignment in the blog above for additional insights.
About The Author - John Smith
John Smith is an experienced Python programmer specializing in software development and education. With a passion for problem-solving, John excels in crafting clear and efficient code. His expertise extends to creating user-friendly programs and providing insightful comments for enhanced understanding.