#🔒 Python Homework - Can't declare variable but need it to complete assignment

37 messages · Page 1 of 1 (latest)

placid bay
#

Good evening! I am having a bit of trouble solutioning my homework. I'm supposed to write a script where I can do inputs and get back certain information YET it is asking for a variable that hasn't been declared and I don't know how to delcare it without actually giving it a figure.

EmployeeBonus.py - This program calculates an employee's productivity bonus.

initialize variables here.

bonus_1 = 50.00
bonus_2 = 75.00
bonus_3 = 100.00
bonus_4 = 200.00

employee_name = input("Enter employee's name: ")
shiftString = input("Enter number of shifts: ")
transactString = input("Enter number of transactions: ")
dollarString = input("Enter transactions dollar value: ")

numShifts = float(shiftString)
numTransactions = float(transactString)
dollarValue = float(dollarString)

Write your code here

score = (dollarValue / numTransactions) / numShifts
if score >= 200.0:
bonus = bonus_4
if score >= 70 and score <= 199:
bonus = bonus_3
if score >= 31 and score <= 69:
bonus = bonus_2
if score <= 50:
bonus = bonus_1

Output.

print("Employee Name:" + employee_name)
print("Employee Bonus: $" + str(bonus))

Error -
Enter employee's name: Kim Smith
Enter number of shifts: 25
Enter number of transactions: 75
Enter transactions dollar value: 40000.00
Employee Name:Kim Smith
Traceback (most recent call last):
File "/workspaces/9780357880876_pld-10e-python-e2683982-f328-4dd7-b897-6609573c97d1/chapter4/ex03/student/EmployeeBonus.py", line 32, in <module>
print("Employee Bonus: $" + str(bonus))
NameError: name 'bonus' is not defined. Did you mean: 'bonus_1'?

How can i declare bonus as a variable to avoid running into post error?

I should be able to fill out
Enter employee's name: Kim Smith
Enter number of shifts: 25
Enter number of transactions: 75
Enter transactions dollar value: 40000.00 and get back

Employee Name: Kim Smith
Employee Bonus: $50

ruby reefBOT
#

@placid bay

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

ornate raptor
#

you have to unindent your code

#

from line 22 to line 27

#

after that make line 22 an elif statement instead of if

placid bay
#

if i do i get an error for an expected indent block

ornate raptor
#

send the error

#

and preferably the code that produces that error too

placid bay
#

Actually let me say this. I initially had the if as elif BUT the first piece of my assignment will fail. Ill give you an example

ornate raptor
#

go for it

placid bay
#

bonus_1 = 50.00
bonus_2 = 75.00
bonus_3 = 100.00
bonus_4 = 200.00

employee_name = input("Enter employee's name: ")
shiftString = input("Enter number of shifts: ")
transactString = input("Enter number of transactions: ")
dollarString = input("Enter transactions dollar value: ")

numShifts = float(shiftString)
numTransactions = float(transactString)
dollarValue = float(dollarString)

Write your code here

score = (dollarValue / numTransactions) / numShifts
if score >= 200.0:
bonus = bonus_4
elif score >= 70 and score <= 199:
bonus = bonus_3
elif score >= 31 and score <= 69:
bonus = bonus_2
elif score <= 50:
bonus = bonus_1

Output.

print("Employee Name:" + employee_name)
print("Employee Bonus: $" + str(bonus))

I just changed it to this

#

visual

ornate raptor
#

wth

#

ok so

#

change the structure

#
if condition:
  code
else:
  if condition2:
    code
  else:
    ...
placid bay
#

that may take a moment

ornate raptor
#

if that doesn't work there's something wrong with the assignment lmao

placid bay
#

it prob is knowing cengage but ill give it a shot

unkempt spindle
ornate raptor
unkempt spindle
#

dang, they force you to write shitty code

ornate raptor
#

ong

placid bay
#

Updated

ornate raptor
#

does it work?

placid bay
#

the first part worked again yes. the second part im checking again.

#

oh both worked, nice

ornate raptor
#

pog

placid bay
#

thanks for the help! is there somewhere I can leave a review?

ornate raptor
#

nah haha

#

you can just close the forum

#

!close

placid bay
#

bet, thank you! hope yall have a great weekend and get raises

#

!close

ornate raptor
#

have a nice rest of your day!

ruby reefBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.