The error message which is in that black pop-up tells you what's wrong. Line 10:
Should probably be:Code:p = computepay(h*r)
You're using an asterisk (*) instead of a comma (,).Code:p = computepay(h,r)
@(you need an account to see links)
Hi everyone! I am currently taking an intro Python course on Coursera and I'm getting an error for a compute function. I went on the course forums an was confused because other students who successfully ran their code/program did not have this error, yet they had the same line of code as me.
This is what I have:
(you need an account to see links)
I'm a total Python newbie, of course, but I've been learning C# and JavaScript on the side when I have some free time and for whatever reason, Python is just taking a lot longer to stick for me. I greatly appreciate any help in advance! I want to be able to understand what I am doing wrong!
The error message which is in that black pop-up tells you what's wrong. Line 10:
Should probably be:Code:p = computepay(h*r)
You're using an asterisk (*) instead of a comma (,).Code:p = computepay(h,r)
@(you need an account to see links)
(you need an account to see links)
(you need an account to see links)(you need an account to see links)
------------------------
[02/24/2013] Stealth CORE is made into the first standalone Neopets auto-player.
------------------------
linttastic(05-31-2020)
(you need an account to see links)
Syntax errors will be the death of me. I hit some other errors after that one, but fixed them right away and was able to run the code successfully. Many thanks for the help!!!
Hi all I'm back Can anyone tell me why the output (where it says mismatch) is generating 'None' for the 'Minimum is' string? I thought I had the syntax entered correctly since it's the same as the string for 'Maximum is':
(you need an account to see links)
Thank you in advance!
Hmm there is a structure problem in your Python code, provide another "tab" at the start of line 9 and line 11.
Try that, maybe that does it!
EDIT: Also because you are printing that invalid input line, (line 14) you might have another failure later on with the output not matching. Just fyi lol
---------- Post added at 10:44 PM ---------- Previous post was at 10:44 PM ----------
Ok so I tried adding another tab to those lines, but the code didnt run. When I moved it back again to where I had it, I was able to run the code, but still showing 'Minimum is' as none. Is the problem with my line 11 since that's where the 'Minimum is' comes from? It's just weird to me since it looks just the same as the 'Maximum is' string and that one printed correctly
Okay so there's two big problems here still.
1) Your TRY and EXCEPT are malformed. What you've done is this:
You need to move the BLOCK 4 under BLOCK 1 because that EXCEPT is not really registering correctly and your structure is just wrong.Code:block 1: TRY block 1-1: num = int(num) block 2: IF#1 block 2-1: IF #1 is true, do this block 3: IF#2 block 3-1: IF #2 is true, do this block 4: EXCEPT block 4-1: EXCEPT for the TRY command before
Two ways to fix the structure are:
#1
#2Code:block 1: TRY block 1-1: num = int(num) block 2: EXCEPT block 2-1: EXCEPT for the TRY command before block 3: IF#1 block 2-1: IF #1 is true, do this block 4: IF#2 block 3-1: IF #2 is true, do this
Code:block 1: TRY block 1-1: num = int(num) block 1-2: IF#1 block 1-2-1: IF #1 is true, do this block 1-3: IF#2 block 1-3-1: IF #2 is true, do this block 2: EXCEPT block 2-1: EXCEPT for the TRY command before
2) 2nd problem. Different programming languages deal with values "None"/null/""/undefined etc differently. In the case of Python, your IF#2 is never being run, because what's happening is that the value of "None" is always lower than no matter any other value you have. To add on to this a bit more, in Python any positive number value I know for a fact will be registered as a higher "value" than "None" which is why you don't need to explicitly do "largest = num" in the code below. I haven't tested enough to see if a negative number will still register as a higher "value" than "None" though, you'll have to test that and let me know hah.
So you need to add somewhere after num = int(num) and before your IF#2 the following:
Code:if smallest is None: smallest = num
I am happy to assist with anything more haha, I think if you make these changes your code will be almost there, it should give you the correct result but there are still things in there which I would have done differently
Last edited by aaronsd; 06-02-2020 at 12:37 AM.
linttastic(06-02-2020)
i'm an uninitiated person to be honest so i've just browsed the web a bit.
Perhaps you can find your answer (you need an account to see links)as they seem to be solving a very similar issue
---
Or just follow the post above as this person is clearly in the known
he's also explaining the same thing as on the page i linked but in a better way.
linttastic(06-02-2020)
@(you need an account to see links)
Thank you thank you thank you!!!! I had a suspicion the TRY and EXCEPT were involved with this, but the lectures and textbook for my course didn't explain it clear enough to apply to my assignment. Same with the 'None' affecting my smallest = num! I was able to get my code to run successfully, but more importantly, understand what I was doing wrong! Super helpful! Thank you again!!!
@(you need an account to see links)
Oh wow thanks for sharing that link! I hadn't thought that someone had posted elsewhere for this course assignment! Helpful to see how other people respond to that issue as well!
Last edited by linttastic; 06-02-2020 at 08:35 AM.