Home > other >  Why can't I get concatenate my dict even after i type str or int?
Why can't I get concatenate my dict even after i type str or int?

Time:12-24

#1 /usr/bin/python

print ('Hi')
age = 4
print (age)
pi = 22/7
print (pi)
time = "2300"
print(int(time) age) 


eten = ("Rice", "Fish", "Stew")
print ("I like eating "  (eten [0]))
print ("I like eating "  (eten [1]))
print ("I like eating "  (eten [2]))
print ("I like eating "  (eten [0])   " and "   eten [2])   

for food in eten:
    print ("I like eating "   food )

x = 1
while x <= 3:
    x = x 1
    print (x)

dict = {}
dict["Jon"] = 23
dict["Tom"] = 24
dict["Ron"] = 28

for age in dict:
    print (age   ' is '   int(dict))

I've gone online to use online debuggers and I'm not getting anywhere. I added str in front and added int and both give me errors.

CodePudding user response:

You can not concatenate Integer with String. The best way to solve your problem is this:

dict = {}
dict["Jon"] = 23
dict["Tom"] = 24
dict["Ron"] = 28


for name in dict:
    print (name   ' is '   str(dict.get(name)))

CodePudding user response:

Try:

for name,age in dict.items():
    print (name   ' is '   str(age))

Instead of..

for age in dict:
    print (age   ' is '   int(dict))

also don't use name dict as it is a built-in data structure in python..

  • Related