Course Solutions Uncategorized (Solved) : Dictionary Hello V 3 3 True Value3 40 H Key Value Dictionaryitems Try Try Try Print Float Q30419615 . . . .

(Solved) : Dictionary Hello V 3 3 True Value3 40 H Key Value Dictionaryitems Try Try Try Print Float Q30419615 . . . .

 

dictionary={‘hello’:’v’,’3′:3, ‘True’:’value3′ ,’4.0′:’h’}
for key,value in dictionary.items():

try:
try:
try:
print(float(key))

except:
print(int(key))
except:
print(bool(key))
except:
print(key)

I have this code, I want to try and convert the keys(which arestrings) into either integers/booleans/floats and return the stringitself if they cannot. However, the output returns this:

True
3.0
True
4.0

I’m not sure why it doesnt return ‘hello’ , returns True twiceand int(3) as 3.0

Expert Answer


An answer will be send to you shortly. . . . .

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post