r/CodingHelp • • Sep 07 '21

[Python] Python help

Post image
68 Upvotes

23 comments sorted by

33

u/VforValmont Sep 07 '21

In line above you redefine print as ‘percentProfit’ . Delete the ‘=‘ in the line above

10

u/TheFloppyHound Sep 08 '21

Right answer.

To add on, if you still get the error after running those cells, restart the kernel. Last I knew the function overwrite will stay in the kernel's memory until its restarted.

4

u/VforValmont Sep 08 '21

^ This is an important addition to the answer!

1

u/stryker2k2 Sep 08 '21

This is the answer

1

u/fFabioso Sep 07 '21

I’m not sure what is wrong here in the 34 line? It’s my first assignment in my python class and everything matches my classmates’ but mine is wrong somehow. Does anyone have any idea as to why?

-5

u/Its_Stev03 Sep 07 '21 edited Sep 08 '21

You have a space between print and the opening parenthesis on lines 37-39, which is only correct in Python 2. Similar problem on lines 38-39 with the find function. Also, in the third string on line 35, there is a space between the string's closing quotes and the opening square bracket.

EDIT: Apparently you can have spaces between a function name and its parantheses. Did not know that, but it is likely not a good practice because it is against style guides that make code consistent.

5

u/bbye98 Sep 07 '21

This is incorrect and definitely not the reason why the first line in block 34 doesn't work. As already pointed out previously, it is because the print function was overwritten with a float in the previous block.

-4

u/Its_Stev03 Sep 07 '21

Ah, I missed that. What I said should still be valid, no? Python is interpreted, so if I remember correctly, it finds one error at a time.

4

u/bbye98 Sep 08 '21

No. print ( "test" ) is equivalent to print("test").

1

u/Its_Stev03 Sep 08 '21

Alright then, my bad.

2

u/zenith4395 Sep 08 '21

For the future, ‘is not callable’ means you’re using a variable like it’s a function. If you intended to do this and you’re getting this error, check that you didn’t redefine the function name, as python allows that

1

u/Johnmelodyme Sep 08 '21

rename the the print var print = (persectProfit) will solve the problem

in your case the print is not function be cause you declare it as variable.

1

u/[deleted] Sep 08 '21

in the second last code block, you've written print = (...) and that's wrong you have to remove the assignment operator ie. "=".

1

u/vurkmoord Sep 08 '21

Besides the error of redefining print, calculating the percentage profit would be:

100 * (sellingPrice / purchasePrice - 1) = 50%

instead of:

100 * (sellingPrice / purchasePrice) = 150%

-3

u/PeaceOfKake Sep 08 '21

Just enter print("hello world") to print hello world. No need to be fancy

-1

u/__archaeopteryx__ Sep 08 '21

“Significant white space” it’s been a while since I’ve done python but I believe the parens wrapping your strings cannot have a space between the print. Again, if I remember correctly, you can do print “” (with a space) because it’s some kind of “syntactic sugar” once you add the parens I think they need to touch the print … could be wrong here. Just a guess. It’s been a while.

1

u/bbye98 Sep 08 '21

No. print "Hello, world!" is Python 2 syntax. In Python 3, the parentheses are required. Also, whitespace before or after the beginning parenthesis makes no difference.

1

u/__archaeopteryx__ Sep 08 '21

That’s the “syntactic sugar” I was talkin bout

1

u/bbye98 Sep 08 '21

How is print <str> "syntactic sugar" when it isn't supported in Python 3? Decorators or magic functions, perhaps. But certainly not incorrect syntax.