r/PythonLearning • • Oct 15 '26

Help Request I’m stuck on this assignment

I never struggle on assignments but this one is so confusing for me

132 Upvotes

66 comments sorted by

•

u/Sea-Ad7805 Oct 15 '26 edited Oct 15 '26

Run this (slightly altered) program by clicking Memory Graph Web Debugger and see its state change step by step.

→ More replies (6)

2

u/kutac56 Oct 15 '26

You need to add " when printing stuff to make it a string and you're doing something weird on line 26 which doesn't seem correct

2

u/Hefty_Courage3893 Oct 15 '26

That’s how the assignment loaded up… not a big fan of the website

5

u/kutac56 Oct 15 '26

Yes. The whole intention of this assignment is to fix the program. Fix it

1

u/Sether_00 Oct 15 '26

Also, line 23 is missing colon and what is suppose to happen after.

1

u/kutac56 Oct 15 '26

Also the logic seems wrong as you're doing >= 31-69 which means that that's true if it's higher han or equal to 31 minus 69 which is -38. You need to reorder your if statements and don't do 31-69

2

u/knight04 Oct 15 '26

Are you trying to calculate which bonus they get or the errors?

2

u/Hefty_Courage3893 Oct 15 '26

Bonus

2

u/knight04 Oct 15 '26

It looks like you need to have a bonus = bonus1/bonus2 before that print on the bottom. Also add " " for the prints

12

u/PureWasian Oct 15 '26 edited Oct 15 '26

Follow the red squigglies. Your print statements need "quotation marks" or 'apostrophes' around the output strings, and your elif is missing a colon* and followup conditional block of code within it

Your code does not run otherwise.

The conditional statements don't do ranges in the way you are trying to do them as. 31-69 evaluates to -38 instead of being treated as a range.

Regarding the actual logic, you haven't given enough information from the problem statement as to why a nested if statement would be necessary instead of a simple if/elif chain (although you could do it as nested ifs if the solution checker demands the less elegant solution though)

3

u/PureWasian Oct 15 '26

Also the description "dividing an employee's transactions dollar value by the number of transactions and then dividing the result by the number of shifts worked" does not line up with the productivity_score calculation on line 17.

No idea if you wrote that or it was provided to you but it does not look to be the correct interpretation of the problem statement.

1

u/BedtimeWithTheBear Oct 15 '26

Small but important nitpick - the elsif is missing a colon (:) not a semicolon (;)

2

u/PureWasian Oct 15 '26

autopilot brain, thank you. Corrected the typo^^

1

u/Hefty_Courage3893 Oct 16 '26

I finished the assignment!!!

1

u/PureWasian Oct 17 '26

Congrats!

4

u/AndroidLex Oct 15 '26

See those red underlined parts? Those appear when there’s something wrong with the code on that location. Once it’s fixed, the line disappears. Good luck!

4

u/igotshadowbaned Oct 16 '26 edited 28d ago • Bravo

For print, if you want it to just print text as a string, you need to put it in quotes

print("You earned a bonus")

If you want to also print a variable, you put it in the list within the function call

print("You earned a bonus", str(bonus_1)

You can alternatively combine the strings first

string = "You earned a bonus" + str(bonus_1)
print(string)

But your syntax is currently the problem.

You do do it correctly later. And then also use fstrings.

You're also missing a semi colon after your last elif statement, which is highlighted

Did you try using AI to write this? I'm just confused how else you would have correctly written sections that do the same thing, but then not be able to figure why it isn't working 6 lines above that

2

u/spidertyler2005 28d ago

Colon* not a semicolon. Just in case they see it before you make an edit

1

u/kyle2143 26d ago

The second screen says that the code was pre-written above the comment in line 18. I think he legitimately tried to write the code and just got the syntax wrong for prints and string concatenations.

1

u/clegg2011 Oct 15 '26

Your line 17 for productivity score looks to be backwards from the way it is described in the homework. As you have it the higher dollar value an employee achieved the smaller their productivity score. The way the assignment lays it out instead a productivity score should scale up with a higher dollar value .

$/transactions/shifts vice shifts/transaction/$

1

u/Hefty_Courage3893 Oct 15 '26

How should that look?

3

u/schals Oct 15 '26

Commenting so I can see. I’m about to start Python so I’m curious.

1

u/BranchLatter4294 Oct 15 '26

Strings go in quotes.

1

u/Adrewmc Oct 15 '26

Line 20 and 22 those need to be inside quote marks to print. It’s also adding the print return(None) to a string not possible.

There is no bonus variable to print on the last line.

1

u/TheCozyRuneFox Oct 15 '26

You are missing question marks around your strings inside of your print statements.

print(blah blah) Will error because Python will think it is looking for a variable or function name blah. Which don’t exist.

print(“blah blah”) Works as the quotes indicate the text inside of there is a string value not code.

Your bonus has a red squiggle. This because you have no variable named bonus—it is trying to get the value of something which does not exist.

Finally, there is an issue with how you are checking if the score is eith in a given range. The hint I will give is that 31-69 will evaluate to -38. Think about how the comparative operators work too.

1

u/bslime17 Oct 15 '26

line 26, can’t see any bonus as variable hence you’ll be getting an error over there

1

u/bslime17 Oct 15 '26

you need to calculate the bonus and call the bonus in line 26

1

u/recentAd1666 Oct 15 '26

A few bug i catched

L22+24 missing double quotes around strings, and bad parenthesis.... Print ("blabla" + str(bonus_1))

L25 missing : and the end of the if structure

1

u/blktndr Oct 15 '26

You are creating output before the output that was already provided for you. Scratch your print()s between lines 19-23 but leave the rest of the logic. All you need to do here is assign the right value to bonus (i.e. bonus = bonus_1). The provided code will handle the rest

1

u/LynneLynette Oct 15 '26

Hmu. I can help

1

u/kvnqstoner Oct 15 '26

line 20, under the if block your print variable should be in qoutes and also your last elif should have a colon

1

u/fth_codexa Oct 15 '26

Print(f"...")

1

u/Living_Fig_6386 Oct 15 '26

Towards the bottom there's a tab labeled "Problems" with the number six. It tells you what is wrong (syntax, it doesn't understand whether your calculations are correct). For example, you might want to compare and contrast your use of print and the print statements that are provided.

Also, I don't believe that your bonus calculate does what you think it does / the assignment asks for. Think about what you are trying to calculate; it's arthmetic.

1

u/Lirianov Oct 15 '26

What course is this from? I don't understand why its taking an input and setting it to an int and then converting that to a float... just set it to an float right away...

First, lines 20 and 22 don't have "" around the print statement and the "+str(bonus1)" should be inside the parenthesis. Should be print("you earned a bonus " + str(bonus_1)). theres no need to turn it to a string btw if you do print("you earned a bonus", bonus_1)

next, your if/elif statements aren't properly written.

line 19 is wrong. you're saying "if productivity score is greater than or equal to 30 -> you get bonus 1" which means you will never trigger the other bonuses.

line 21 is saying "if productivity score is greater than or equal to 31 minus 69." What you're trying to say is "if productivity score is greater or equal to 31 AND productivity score is less than or equal to 69."

line 23 has the same problem as line 21 plus it also is missing the colon at the end plus the code you want it to execute.

line 26 is trying to print "bonus" which doesnt exist

fix those and run it again.

does it show you what it wants as the output to be?

1

u/Intrepid_Balance6127 Oct 15 '26

Look into the range() function. Also, it’s okay to struggle when learning to code. I struggle all the time. It’s a part of the process, and usually ends in learning something if you stick with it. Anybody that says programming is easy to learn is a liar!

1

u/Practical-Pie93 Oct 15 '26

Line 12, should be a float, not int

1

u/blavek Oct 15 '26

Your logic in the if's where you are trying to calculate the bonus doesn't work. Your first if is checking if the score is >= 30 but the given range is <= 30 for bonus 1. As others have mentioned in the if the code will evaluate 31-69,, then check if it is >= to the result. I don't know if your teacher warned you or not but you can get fractional results from the productivity calculation. The test example the assignment provides, for example, evaluates to 40000 / 75 / 25, which, when calculated, is 21.333... With your logic, if the result is 30.5, it won't fall into any of those ifs you have prepared. If you need a continuous range, you need to use both <= and a >. What I mean is you need to test if it is <= 30 for the first range, and the second range would be > 30. So anything that equals 30 or below will get into the first range. Then anything above 30 would fall into the second range. If you use >= 31 then you are missing anything > 30 and < 31. The assignment is poorly worded, at least where it defines your ranges. I don't see anywhere that it is telling you how to handle a 30.6, for example. The same problem exists between the second and 3rd range.

The next kind of hurdle based on the assignment is that you have to use nested ifs. This is not a great assignment for nested ifs, and I think, confuses the problem further. You will need a construction like this. I find this to be pretty ugly, and the code itself doesn't explain the problem being solved.

bonus = 50
if productivityScore > 30:
  bonus = 75
  if productivityscore > 70:
    bonus = 100

print(bonus)

1

u/khosrua Oct 15 '26

Wait why does it have to be nested ifs? Did I miss something?

2

u/blavek Oct 16 '26

It's in the assignment in the 3rd picture

1

u/khosrua Oct 16 '26

Ugh hate arbitrary requirements.

1

u/Current-Fix615 Oct 16 '26

I dont see the variable bonus defined.

1

u/ungiornoallimproviso Oct 16 '26

Use the problems tab, lint is your friend.

1

u/deadeye_82_1 Oct 16 '26

Quotes are missing in line: 20, 22
`bonus` which is used in line 26, does not exist. You have bonus_1, bonus_2, bonus_3, bonus_14

1

u/TheOneArmedLogan Oct 16 '26

Technically there’s a few things wrong, but I’m not going to go too deep. The very first thing I noticed though was the prints not having quotation marks.

1

u/Adorable-Strangerx Oct 16 '26

Dear brother, never ever under any circumstances, no matter who, when, why, or how tell you to... don't use float for calculating money... How would you feel if you ended with 0.1000000000000000055511151231257827021181583404541015625 on your bank account? How you you withdraw that at ATM?

1

u/Abhigyan-das Oct 16 '26

Bro, why the fuck have you not give " " in print, and where is the second elif statement colon and work and also where is the bonus variable? Define it as a global variable, so that you can use it anywhere.

1

u/Opussculum Oct 16 '26

Print search there is your problem

1

u/Xqate Oct 16 '26

Use a f string 😭🙏

1

u/g-land-g Oct 16 '26

You have to use quotes in side print

And bonus is missing _1 or 2 or 3

1

u/Silentwolf99 Oct 17 '26

how to create this companion file is that a vs code extension or a .html file can someone pls guide me....

1

u/scrapmakerzayn Oct 17 '26

Check 23 you forget to wrote something:)

1

u/Longjumping_Put_7212 29d ago

ok so I would say that you should start by writing out your logic in pseudocode. While it sucks to do pseudocode for everything, it can be extremely helpful for understanding where you went wrong in your programming. And I recommend only doing one task at a time, so once the first task is done, move to the second one instead of falling down the rabbit hole of doing two tasks at once.

1

u/ImLloydM8 29d ago

What learning platform is this out of interest? Thanks.

1

u/being_unknown112 27d ago

1st: take float as input; instead of converting integer to float

2nd: use simple braces in productivity formula to make it more readable: (num_shifts/num_transactions)/ dollar_value Still update the formula: else it will not execute any if else block

3rd:use " " or ' ' in print statement for printing a string; print("Hello World!")

4th: if -eligibility blocks are not complete; use the other bonuses as well; bonus_3, bonus_4.

5th: bonus is not declared, so it will throw an error.

1

u/dimipio Oct 16 '26

I think that a library if it is allowed it would help

0

u/DebateLittle 29d ago

Use chat gpt

0

u/Rare_Coffee_130 Oct 15 '26 edited Oct 15 '26

1.- You need to cover your message inside print() with " ", ' ' or string literals (my favorite) adding f before double quotes like this: print(f"You earned a BONUS").

With string literals you can insert variables inside your string message with curly braces { } like this: print(f"You earned a BONUS {bonus_1}").

2.- Any conditional statement (if, elif, else) needs a colon ( : ) to indicate the end of the conditional and also the start of your code block. Just like the way to have it in your if and the first elif conditional.

3.- It seems that you don't have a variable named "bonus", you have bonus_1, bonus_2, bonus_3 and bonus_4. So you just need to change it to whatever variable you want to display. (Btw, that last print that you have in line 26 is the string literal that I mentioned in my first point, you don't need to use str() method, f string literal will "see" or "take" whatever is in { } as a string).

Good luck, buddy! You can do it :)

0

u/mechanicalyammering Oct 15 '26

When you run it and input data, what happens? Also look at what VS code is highlighting in red. Why is it throwing errors at you?