I'm solving the Python 300 for beginners
ice_cream = {'Merona': 1000, 'Papico' = 1100}
To output melona price: 1000
in
I wrote print('Melona Price:'(ice_cream['Melona']))
but they said str
didn't work.
print('Melona Price:',(ice_cream['Melona']))
is the answer, but I don't know what str
has to do with str
instead of spacing one.
I'm sorry to ask you something basic because I'm a beginner. I'd appreciate it if you could explain it in detail
python
In Python, a combination of strings and numbers is often used in one of three ways.
Many people are confused that print(1000)
works as intended.
The reason why print('count: ' + 1000)
is error is because 'count: '
and 1000
cannot be added.
Below is an example of how the code you uploaded was modified to work correctly.
ice_cream = {
Melona: 1000,
Papico: 1100
}
# 1. Output using casting
print('Melona Price:' + str(ice_cream['Melona'])))
# 2. Output using commas
print('Melona Price:', ice_cream['Melona'])
© 2025 OneMinuteCode. All rights reserved.