Problems with creating better solutions than needed

lesson link:

So I got the free trial to keep me busy since I’ve been made redundant and to brush up on my python amongst other things.
I’ve been having a lot of problems with the lessons, not because I am struggling with the solutions but because I am creating what I feel are better solutions than needed and even when I dumb them down I am still met with various errors and can’t progress, such as below;

My answer for task 1 in the link above:

def greater_than(x, y):

if x == y:

print("These numbers are the same")

elif x > y:

print((str(x) + " is greater than " + str(y) + "."))

elif x < y:

print((str(x) + " is smaller than " + str(y) + "."))

greater_than(1, 1)

now I’ve checked this code in Pycharm and even saved it as a script and been able to run it fine in cli yet I am met with error after error in the lesson, currently " Expected greater_than with test inputs 7 and 3 to return 7" I can run the program, change the numbers yet this error still occurs only the input numbers change each time, even when using the number they claim were expected still returns the same error but changed the input numbers.

and since support can’t provide support for any code, I am pointed to these forums.

anyone else having these problems or have a solution to them?

Hey there @adam8078009507! Welcome to the forums :grinning:

From what I understand the lessons ususally check answers based on the output recieved, which is why it did not except your answer.
It will also check different parts of the code structure, such as making sure you used an if/else statement instead of:

def greater_than(x, y):
  return x

print(greater_than(5, 1):

I have run into the same problem a few times, so I will usually finish the lesson and then modify after with improvements.

1 Like

Currently, your code uses the print function to print out a concatenated string . However, the exercise is asking you to use the return function.

Welcome to the forums @adam8078009507 !


Thanks for both your replies.

First answer, I gave up and just asked for the solution and it was barely any different from my solution, in fact it was more lines of code than my solution, but still returned the same results. I’ve had a lot of problems like this where is you don’t give the exact secret answer they are looking for it just keeps telling you that you’re wrong!

Second answer, I did play about changing it from print and return then printing the final function result but again because i didnt use the exact secret code they wanted I was wrong and again my answers used less code and gave better output results rather than just a single number.

so far I’ve spent most of my time on here getting annoyed at the courses telling me I’m wrong because I haven’t wrote the code exactly how they want me to yet I still produce the same results, I had similar problems earlier in the course with the train aha but google assured me I wasn’t the only person having the same problems.

Though you may see your answer as better, perhaps look at it differently. When you are designing a program you can have it work how you want it to.

However in this case someone else is asking you for a program to meet their specific needs.

They don’t want a string to be returned, they need the number. Perhaps they are planning to do something with that number that they can’t do with a string such as add it to another integer.

If you give them a function that returns a string and then they try to use that value in a way that requires an integer or float, their program throws an error:

>> a = 5
>> b = 'your returned string'
>> c = a + b
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Since you can write your own program after completing the task, the lesson is actually giving you good practice.

1 Like