0 points Show
Submitted by Zh Q over 7 years Hi, I would appreciate any help with my code as followed def hotel_cost(days): return 140days def plane_ride_cost(city): if(city==”Charlotte”): return 183 elif(city==”Tampa”): return 220 elif(city==”Pittsburgh”): return 222 elif(city==”Los Angeles”): return 475 def rental_car_cost(days): cost=40days if(days>=7): cost=cost-50 elif(days>=3): cost=cost-20 return cost def trip_cost(days,city,spending_money): sum=hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)+spending_money return sum And I was kept telling something like ‘Oops, try again. trip_cost(‘Pittsburgh’, 4, 0) raised an error: cannot concatenate ‘str’ and ‘NoneType’ objects’ I tried to change “” to ‘’ but it didn’t work. Thanks again. Answer 54a1a8fe937676dae7015774Hi, I suggest that you define a function called spending_money(money) that returns money. Then, you simply add money to the arguments of the trip_cost function and also add spending_money(money) to the sum. Regards, Matt points over 7 years Answer 54a5f2b276b8fec6290020f4Hi Calvin, I think that you should make your spending_money function return money so that you actually get the function to work. Regards, Matt points over 7 years Answer 54a32ac476b8fec921018063Im having the exact same problem. There seems to be an issue with the “plane ride” part of the code but that is a given and worked fine in a previous problem, so I don’t know why it won’t work now. my code is 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”): return 475 def rental_car_cost(days): def trip_cost(days, city, spending_money): return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days) + spending_money(money) points over 7 years Answer 54a130d076b8fe9670013922In your def tripcost statement, spendingmoney is one word. In your sum statement near the end, spending_money has an underscore between the two words. points over 7 years Answer 54a454c095e3788cec0002beHaving similar problems, hope you can help. It’s telling me that I need an indent on my trip_cost function. 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”: return 475 def rental_car_cost(days): rental_car_cost = days * 40 if days >= 7: rental_car_cost -= 50 elif days >= 3: rental_car_cost -= 20 return rental_car_cost def spending_money(money): def trip_cost(city,days,money): sum = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money(money) return sum points over 7 years Answer 54be92c351b887d2330029e1points over 7 years can only concatenate str (not NoneType) to str errorQuestions : can only concatenate str (not NoneType) to str error2022-09-17T19:06:31+00:00 2022-09-17T19:06:31+00:00 808 I am making a ROBLOX account checker using anycodings_python-3.x robloxpy. (Python 3.x) And when i execute anycodings_python-3.x the code it gives me this error:
Here is the code:
Total Answers 1 24 Answers 1 : of can only concatenate str (not NoneType) to str error
My guess is some players just don't have anycodings_python-3.x a RAP (recent average price) attribute anycodings_python-3.x so it returns None -- either you can anycodings_python-3.x replace this by a '' or '0':
or you can just straight out print out anycodings_python-3.x the None:
Might have to apply this to the other anycodings_python-3.x attributes as well. 0 2022-09-17T19:06:31+00:00 2022-09-17T19:06:31+00:00Answer Link mRahman How do you fix TypeError can only concatenate str not NoneType to STR?The Python "TypeError: can only concatenate str (not "NoneType") to str" occurs when we try to concatenate a string and a None value. To solve the error, correct the assignment or check if the variable doesn't store a None value before concatenating.
How do you fix TypeError can only concatenate str not list to STR?The Python "TypeError: can only concatenate str (not "list") to str" occurs when we try to concatenate a string and a list. To solve the error, access the list at a specific index to concatenate two strings, or use the append() method to add an item to the list.
Can only concatenate str not function to str?Conclusion # The Python "TypeError: can only concatenate str (not "set") to str" occurs when we try to concatenate a string and a set. To solve the error, use a formatted string literal, or use the add() method to add an item to the set.
Can only concatenate str not tuple to STR in Python?The Python "TypeError: can only concatenate str (not "tuple") to str" occurs when we try to concatenate a string and a tuple. To solve the error, access the tuple at a specific index to concatenate two strings, or use a formatted string literal.
|