I started learning python and Im struggling with functions. Whats wronge with this code? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

I started learning python and Im struggling with functions. Whats wronge with this code?

def compare(value,money): total=money-value if money>value: return total else: print("Cannot Afford") print(compare(50,5000)) Also, I apologize if it is just a stupid mistake I didn't notice

7th Apr 2020, 11:31 PM
Elias Kamakas
Elias Kamakas - avatar
5 ответов
+ 3
The return statement should be indented
7th Apr 2020, 11:44 PM
Justus
Justus - avatar
+ 2
I'm also rather new at Python, but I believe the problem is that the "return total" line should be indented. When that is done your code compiles.
7th Apr 2020, 11:40 PM
Elseif
+ 1
you need read function in python as more detail , it's best way for you best regards
7th Apr 2020, 11:36 PM
Zandi
Zandi - avatar
+ 1
Thanks a lot to everyone!
8th Apr 2020, 12:03 AM
Elias Kamakas
Elias Kamakas - avatar
+ 1
def compare(value,money): total=money-value if money>value: return total else: print("cannot afford") print(compare(50,5000))
8th Apr 2020, 5:19 AM
Ashish Singh
Ashish Singh - avatar