Python Forum
i need help with this code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: i need help with this code (/thread-16778.html)



i need help with this code - klittle01 - Mar-13-2019

hi all can some one please help me write and understand this code as I am new and trying to learn I can do basic if statement but I cant seem to get this one to work
the flow chart is in the link thank you in advance
https://groklearning-cdn.com/problems/djZjT3sQjPi4B2gQbt8adJ/transportation_flowchart.png


RE: i need help with this code - micseydel - Mar-13-2019

Please share your code attempt (in code tags - we don't want a screenshot of it) along with any input, actual output, desired output, or anything else that can help us to help you.

(Whether intentionally or not, posts like this come across as "do it for me" and only tend to replies like this one.)


RE: i need help with this code - klittle01 - Mar-13-2019

sorry for that this is what I have so far

value = input("is it raining")
if value == 'yes':
print("take the bus")
if value == "yes"
decision = input("how far in km do you need to travel")
if desision '=<2km':
  print("walk")



RE: i need help with this code - stullis - Mar-14-2019

There are a few items to fix with your current code other than indenting (which could be a copy-paste issue). The first two if statements are evaluating the same thing. As a result, this will always print "take the bus" and ask "how far..." when the first answer is "yes". According to the flow chart, the question should only be asked if the first answer is "no". The code needs an elif to correct that.

The other major problem I see is the third logic expression. The flow chart indicates that one should walk only when the distance is less than 2km, not when it is 2km or less. Plus, it isn't comparing anything right now. This can be fixed by converting the input() to a number and then comparing it to 2.

value = input("is it raining")
if value == 'yes':
    print("take the bus")
elif value == "no"
    decision = float(input("how far in km do you need to travel"))
    if desision < 2:
      print("walk")



RE: i need help with this code - klittle01 - Mar-14-2019

thank you yeah I need to add 2 more varibles to it