Python Forum

Full Version: i need help with this code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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/dj...wchart.png
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.)
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")
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")
thank you yeah I need to add 2 more varibles to it