After I finished ep.8 (taking a vacation) last lesson I came back to it and tried to the same but with raw input.
I screenshotted the code here : https://gyazo.com/3e4fce0e288936b7767e36ce38b344bf
The code worked fine before I changed it to this. I can write the answers on the output console but then this bug shows... I don't know what to do and I still try to figure out all the raw_input thing (they didnt use it much after the first explanation).
If you can help me it will be very nice (:
and of course i would like to know how to fix the code too
raw_input() returns Unicode. Your three functions all take Int in their parameters so some conversion of the inputs is necessary.
city = int(raw_input( ... )) days = int(raw_input( ... )) spending_money = int(raw_input( ... )) print trip_cost(city, days, spending_money)
thanks, but where am i supposed to write those? inside the trip cost function? in line 25? where?
btw how can i wrtie codes in the forum like you did?
The code above is written with four leading spaces on each line. This is known as basic block format.
We can preserve the formatting of program code and give it syntax highlighting with three backticks before and after the code block sample.
See this page for more details:
As to your first question, the exercise does not actually ask us to get user input, just call the function at the end. See the instructions and be sure to complete that last step. The above example code can be pasted at the very end, and may be rejected by the SCT, so pass the lesson first, then try that code.
I passed the lesson without it before I put the raw input. I just wanted to try putting raw input cuz they dont really explain how to use raw input in functions anywhere, and it makes more sense to put there raw input so the program can be somehow useful (if all the written values are right)
its working!!! thanks for the help!
def hotel_cost(nights): return 140*nights def plane_ride_cost(city): if city == "Charlotte": return 183 elif city == "Tampa": return 220 elif city == "Pittsburgh": return 222 elif city == "Los Angeles" or "LA": return 475 def rental_car_cost(days): car_cost = days*40 if days >= 7: car_cost -=50 elif days >= 3: car_cost -=20 return car_cost def trip_cost(city,days,spending_money): return hotel_cost(days) + plane_ride_cost(city)+rental_car_cost(days) + spending_money days = int(raw_input('how much time is the vacation?')) city = raw_input('where are u going?') spending_money = int(raw_input('how much money are you planning to spend?')) print trip_cost(city,days,spending_money)
"LA" doesn't get compared to
city here. That expression is always truthy regardless of what value
if "blah blah": print "strings are truthy" print 0 or "and or is incredibly simple, as in dumb"
strings are truthy and or is incredibly simple, as in dumb
ionatan that wasn't the problem. it works fine with 'LA'
I'm not saying it's the problem. Your function exhibits correct behavior, but that comparison does not do what you think it does.
Your function will return 475 for any input that doesn't match one of your cities. Because that "condition" is always truthy.