Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need help with this code
#1
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
Reply
#2
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.)
Reply
#3
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")
Reply
#4
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")
Reply
#5
thank you yeah I need to add 2 more varibles to it
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020