此代码有问题,我无法解决。我是Python的初学者
对于菜单3,我想获取每个员工的薪水并计算他的收入,但是代码没有进展。
对于菜单4,我想显示允许员工工作的天数
尽管尝试了一切,我还是无法运行它。你能帮助我吗?
menu = 0
while menu != 6:
menu = int(input("1. Enter Data: "))
if menu == 1:
fin = "data.txt"
fout = open(fin, 'w')
info = ""
no = 0
while info != "no":
info = raw_input("Veri girmek istiyor musunuz? (yes/no)")
if info != "no" and info == "yes":
try:
no = no + 1
weekdays1 = int(input("09:00-17:00"))
weekdays2 = int(input("17:00-09:00"))
weekend1 = int(input("09:00-17:00"))
weekend2 = int(input("17:00-09:00"))
freeday = int(input("bu eleman haftada kac gun izinli"))
totalweekdayshour = (weekdays1 + weekdays2) * 5
totalweekendhour = (weekend1 + weekend2) * 2
totalhour = totalweekdayshour + totalweekendhour
n = int(input("cash for hour"))
m1 = (weekdays1 * 5) * n
m2 = (weekdays2 * 5) * (1.5 * n)
m3 = (weekend1 * 2) * (2 * n)
m4 = (weekend2 * 2) * (2.5 * n)
totalsalary = m1 + m2 + m3 + m4
if weekdays1 >= 9 :
if weekdays2 >= 9 :
if weekend1 >= 9 :
if weekend2 >= 9 :
print ("Hatali calisma saati girisi")
except:
print("Oops! Enter a number.")
fout.write("%s, %s, %s, %s, %s, %s, %s, %s, %s, %s \n" % (
no, weekdays1, weekdays2, weekend1, weekend2, totalweekdayshour,
totalweekendhour, totalhour, totalsalary,
freeday))
fout.close()
#all work hours for each worker
elif menu == 2:
print "2. Selection"
fin = open("data.txt", "r")
for line in fin:
mylist = list(line.split(","))
no = mylist[0]
totalweekdayshour = mylist[5]
totalweekendhour = mylist[6]
totalhour = mylist[7]
print 'No : ', no
print 'Total hour : ', totalhour
print 'Hafta ici calısma saatleri: ', totalweekdayshour
print 'Hafta sonu calısma saatleri: ', totalweekendhour
print ""
fin.close()
#collecting the salary of each employee and calculating the revenue doesn't
work
elif menu == 3:
fin = open("data.txt", "r")
totalexpence = []
i = 0
a1 = 0
for line in fin:
totalexpence.append(line.split(","))
a1 = a1 + float(totalexpence[i][8])
i = i + 1
fin.close
print "4.selection"
print ("Total expence:", a1)
print ""
#shows how many days the employees are allowed (doesn't work)
elif menu == 4:
fin = open("data.txt","r")
i=0
n=0
freeday=fin.read()[i][9]
i=i+1
print freeday
#doesn't work
#45h law
elif menu ==5 :
fin = open("data.txt","r")
for line in fin:
totalweekdayshour= [5]
totalweekendhour= [6]
if totalweekdayshour + totalweekendhour >= 45 :
print ("employees should not work more than 45 hours per week.")
else:
print ("working hours approved")
fin.close()
答案 0 :(得分:0)
Python语法基于缩进,例如C,您可以在其中使用{}将代码分组在一起。
Python代码(必须在缩进位置):
if my_condition:
foo('bar')
elif other_condition:
baz()
else:
print 'no condition met'
C ++(请注意,缩进可以是不规则的,而无需任何功能更改):
if (my_condition) {
foo("bar");
} else if (other_condition) {
baz();
} else std::cout << "no condition met" << std::endl;
其含义是缩进会改变行为!每次缩进将缩进的代码“属于”到最后一条未缩进的行(以“:”结尾)时,无论是if语句,while循环还是其他语句。请参见下面的示例:
if my_condition:
print 'this line belongs to the if'
print 'this line does not'
因此,第一个建议是清理缩进并考虑它将如何影响代码。
也: