In: Computer Science
- Imagine each of the following items is a piece of information and we want to define a variable in Python to keep the value of these items in the memory of the computer. For instance, in order to represent a person age, we can define a variable like the following variable and initialize it with a sample value:
age = 23, the type is integer
- For each of the following items, define a variable and initialize it with a sample value and explain what data type or data structure you would use to represent the item.
- Student number
- Student number of students in CSCI120
- Your car model (for instance BMW)
- An .mp3 music file (for example: mySong1.mps)
- The information of the following table: First column is the item and the second column is the
weight of the item.
Item
iPhone iPad
cup keychain watch
-
Weight (lb) |
Item |
Weight (lb) |
10 |
Tea box |
9 |
12 |
notebook |
16 |
5 |
ring |
2 |
7 |
battery |
5 |
13 |
sanitizer |
7 |
# Student number
studentNumber=23
#using an integer data type to store the value
#Student number of students in CSCI120
studentNumbers=[1,2,3]
#using a list of integers
#Your car model (for instance BMW)
carModel = 'BMW'
#using string data type
#An .mp3 music file (for example: mySong1.mps)
song = 'mySing1.mps'
#using string datatype
#The information of the following table: First column is the
item and the second column is the weight of the item.
data={"iPhone":10,"iPad":12,"cup":5,"keychain":7,"watch":13,"Tea
box":9,"notebook":16,"ring":2,"battery":5,"sanitizer":7}
#using a dictionary to store key value pairs, where keys are string
data type storing item names, and values are integers
#storing weight