i'm trying to implement this code. here are the problems:
1. i want to use variable typ_transport in further coding not just inside if.(it does not recognize the variable.)
2. the logic seems to be right but when i change the values in jsonStr (e.g. "walk" : true to "walk" : fasle ) the output does not print the right output.
Could any one help me with this? thanks
import json
jsonStr = '{"walk" : true, "bike" : false, "tram" : false}'
inputvar = json.loads(jsonStr)
if inputvar['walk'] == 'True' and inputvar['bike'] == 'False' :
typ_transport='foot'
elif inputvar['walk'] == 'False' and inputvar['bike'] == 'True' :
typ_transport='bicycle'
class transport:
if typ_transport=='foot':
velocity=80
typ='foot'
elif typ_transport=='bicycle':
velocity=330
typ='bicycle'
def __init__(self,typ,velocity):
self.velocity = velocity
self.typ = typ
if inputvar['tram'] == 'False' :
radius= T*transport.velocity
print (radius)
else :
print (typ_transport, 333)
Aucun commentaire:
Enregistrer un commentaire