简体   繁体   中英

Can someone scan over this Python code that I wrote and let me know what I did wrong?

I have to write a program for my Computer Logic class, and I can't figure out why this won't run. The error I keep getting is IndentationError: expected an indented block (<string>, line 3) Can someone please point me in the right direction? If there are any mistakes you find, please let me know. This code has to be able to run properly. Thanks.

while True:

cname = 'My Company'
drate = .17
maxhrs = 40
pdate = "9/1/2015"
orate = 1.5
lc = 'Y'
while(lc == 'Y'):
ename = raw_input("Enter employee's name.")
dcode = raw_input("Enter department code.(1 - Shipping 2 - Mngmt.)")
hworked = float(raw_input("Enter total hours worked."))
prate = float(raw_input("Enter your pay rate."))
inscost = float(raw_input("Enter the cost of insurance."))
city = float(raw_input("Enter your city code.(1 - Sumiton 2 - Hamilton)"))
st = raw_input("Enter your state")
sex = raw_input("Enter your sex.(M - Male F - Female)")
yrsemp = raw_input("Enter total years employed.")

print("Welcome to our company: ", cname)
print("Pay period date: ", pdate)
    if(sex == 'M'):
        sexword = 'Male'
        else:
        sexword = 'Female'
print("Employee name: ", ename, "Sex: ", sexword)
    if(city == '1'):
        cityn = 'Sumiton'
        else:
        cityn = 'Hamilton'
print("City: ", cityn, "State: ", state)
    if(dcode == '1'):
        dname = 'Shipping'
        else:
        dname = 'Management'
print("Department name: ", dname)
rpay = maxhrs * prate
print("Regular pay: ", rpay)
opay = [(maxhrs - hworked) * orate] * prate
print("Overtime pay: ", opay)
gross = rpay + opay
print("Gross before deduction: ", gross)
damt = drate * gross
print("Deduction amount: ", damt "Insurance cost: ", inscost)
npay = gross - (damt + icost)
print("Net pay: ", npay)
new = raw_input("Would you like to start over with a new person? yes/no")
    if(new = 'yes')

restart = int(input("Press 1 to try again, 0 to exit. "))
    if(restart == '1'):
        continue
        elif(restart == '0'):
        break       
        else:
        print("Invalid input. Please enter 1 to restart or 0 to exit.")

`

Your code is missing indentation after the first while. You need to indent the statements that will run within this loop, also do the same with the second while you have on line 9.

In Python, after a colon must indent(recommend 4 space). So the indent should be like this:

while True:
    cname = 'My Company'
    drate = .17
    maxhrs = 40
    pdate = "9/1/2015"
    orate = 1.5
    lc = 'Y'

while(lc == 'Y'):
    ename = raw_input("Enter employee's name.")
    dcode = raw_input("Enter department code.(1 - Shipping 2 - Mngmt.)")
    hworked = float(raw_input("Enter total hours worked."))
    prate = float(raw_input("Enter your pay rate."))
    inscost = float(raw_input("Enter the cost of insurance."))
    city = float(raw_input("Enter your city code.(1 - Sumiton 2 - Hamilton)"))
    st = raw_input("Enter your state")
    sex = raw_input("Enter your sex.(M - Male F - Female)")
    yrsemp = raw_input("Enter total years employed.")

print("Welcome to our company: ", cname)
print("Pay period date: ", pdate)

if(sex == 'M'):
    sexword = 'Male'
else:
    sexword = 'Female'
print("Employee name: ", ename, "Sex: ", sexword)

if(city == '1'):
    cityn = 'Sumiton'
else:
    cityn = 'Hamilton'
print("City: ", cityn, "State: ", state)

if(dcode == '1'):
    dname = 'Shipping'
else:
    dname = 'Management'
print("Department name: ", dname)

rpay = maxhrs * prate
print("Regular pay: ", rpay)
opay = [(maxhrs - hworked) * orate] * prate
print("Overtime pay: ", opay)
gross = rpay + opay
print("Gross before deduction: ", gross)
damt = drate * gross
print("Deduction amount: ", damt "Insurance cost: ", inscost)
npay = gross - (damt + icost)
print("Net pay: ", npay)
new = raw_input("Would you like to start over with a new person? yes/no")
if(new = 'yes')

restart = int(input("Press 1 to try again, 0 to exit. "))
if(restart == '1'):
    continue
elif(restart == '0'):
    break
else:
    print("Invalid input. Please enter 1 to restart or 0 to exit.")

(by the way, your code has a lot of problems...I can't even understand this is Python 3 or Python 2...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM