A great Python tutorial can be found here on Python official website:
https://docs.python.org/3/tutorial/index.html
You can either use an online IDE such as https://repl.it/ or anything else such as PyCharm. But the point is to get you started asap and move quickly.
On 9/23/2018, some of you finished the first ACSL problem - ACSL_timesheets in Python.
Please reply to this thread with your solution so I know your progress. Thanks!
For checkers, you might want to think along the line what data structure is the easiest to decide if a "jump" is available. The goal is to count the potential jumps, not to simulate the checker board. You only need to evaluate one move: say (1,5) is your position, the only possible jump is your opponent occupies (2,4) or (2,6). So you only need to check if (2,4) or (2,6) is occupied. If yes, then check (4,2) and (4,4) if (2,4) is occupied; or (4,6) and (4,8) if (2,6) is occupied. Running through all the number pairs and update a counter accordingly would give you the result.
Notice you have: line1 = int(line1) before the for loop.
The error message says because you have turned line1 into "int", you can't use line1[0] to refer to the first number.
e.g. if the input is "1,1,5,2,2,6,4,6", after replace(",", ""), line1-"11522646", then you set it as int, which is 11522646, now line1 is an int. You can't use line1[0] to get 1.
Thank you all. It's fun to read your work...
SC, both sample and test data run just fine. Now it's time to think about how to read files so you can process data quicker next time.
KC, nice job :) -- except one line of test data returns 0: 20, 5, G. I know you can fix it so please look into it and let me know what's the glitch.
TD, great job on finding split() function. It is much faster. I will recommend everyone else use this function in the future. But - , split() returns a list - seems you messed up the variable mappings. Please see my comments below. This version runs correctly for both sample and test data. Please fix your code and let me know when it gets the correct results.
--------------------
total = 0 line = input("enter first line") #3, 9, H line2 = input("enter second line") #17, 1, E line3 = input("enter third line") #20, 5, G line4 = input("enter last line") #15, 2, 8 for i in range(4): if (i == 0): line1 = line elif (i==1): line1 = line2 elif (i==2): line1 = line3 elif (i==3): line1 = line4 c = line1.split(",") # This creates a list, assign it to c #print(c) location = float(c[0]) # first in the list is location b = c[1] # second in the list is starting time check = c[2] # third in the list is the ending time, your check if (c[2]=="1"): # you used c[1] previously, which is the starting time??? check=9 elif (c[2]=="2"): check=9.5 elif (c[2]=="3"): check = 10 elif (c[2]=="4"): check = 10.5 elif (c[2]=="5"): check = 11 elif (c[2]=="6"): check = 11.5 elif (c[2]=="7"): check = 12 elif (c[2]=="8"): check = 12.5 elif (c[2]=="9"): check = 13 elif (c[2]=="A"): check=13.5 elif (c[2]=="B"): check = 14 elif (c[2]=="C"): check = 14.5 elif (c[2]=="D"): check = 15 elif (c[2]=="E"): check = 15.5 elif (c[2]=="F"): check = 16 elif (c[2]=="G"): check = 16.5 elif (c[2]=="H"): check = 17 if (b=="1"): # Your original code has a few "==" mixed with "=" when assigning values to b. Moreover, b=9 elif (b=="2"): # comparison string has extra white spaces! That's why the comparison was never b=9.5 elif (b=="3"): # successful so b is never changed. That's why the total is not calculated correctly. b=10 elif (b=="4"): b=10.5 elif (b=="5"): b=11 elif (b=="6"): b=11.5 elif (b=="7"): b=12 elif (b=="8"): b=12.5 elif (b=="9"): b=13 check = float(check) b = float(b) #print(check, b, check-b)
# the calculation below are all correct! if (location<10): print ("$", end=str(10*(check-b))) print ("0") total = total+10*(check-b) elif (location>10 and location<20): if ((check-b)>4): print ("$", end=str(32+12*((check-b)-4))) print ("0") total = total + 32+12*((check-b)-4) else: print ("$", end=str(8*(check-b))) print ("0") total = total+8*(check-b) elif (location>19 and location<30): if ((check-b)>4): print ("$", end=str(48+24*((check-b)-4))) print ("0") total = total + 48+24*((check-b)-4) else: print ("Ur doo doo, I don't know what location that is.") print ("$", end = str(total)) print ("0")
total = 0 #total income line = input("") #3, 9, H line2 = input("") #17, 1, E line3 = input("") #20, 5, G line4 = input("") #15, 2, 8 for i in range(4): if (i == 0): #in each new loop, line1 is replaced by other inputs line1 = line elif (i==1): line1 = line2 elif (i==2): line1 = line3 elif (i==3): line1 = line4 location,b,c = line1.split(",") #takes away the comments location = float(location) #location can now be used for math check = c[1]; #default of check variable if (c[1]=="1"): #replacing 1 with actual time (9:00) check=9 elif (c[1]=="2"): check=9.5 elif (c[1]=="3"): check = 10 elif (c[1]=="4"): check = 10.5 elif (c[1]=="5"): check = 11 elif (c[1]=="6"): check = 11.5 elif (c[1]=="7"): check = 12 elif (c[1]=="8"): check = 12.5 elif (c[1]=="9"): check = 13 elif (c[1]=="A"): check=13.5 elif (c[1]=="B"): check = 14 elif (c[1]=="C"): check = 14.5 elif (c[1]=="D"): check = 15 elif (c[1]=="E"): check = 15.5 elif (c[1]=="F"): check = 16 elif (c[1]=="G"): check = 16.5 elif (c[1]=="H"): check = 17 if (b==" 1"): #I added a space because b will always be: " x" b=9 elif (b==" 2"):#Same with a: " x" (but I made variable "a" a float, so b=9.5 elif (b==" 3"):#there shouldn't be extra spaces b=10 elif (b==" 4"): b=10.5 elif (b==" 5"): b=11 elif (b==" 6"): b=11.5 elif (b==" 7"): b=12 elif (b==" 8"): b=12.5 elif (b==" 9"): b=13 check = float(check)#for math b = float(b)#for math
if (location<10):#different locations mean different incomes print ("$", end=str(10*(check-b)))#in order to add that 0 print ("0")#so I can print in the cents form total = total+10*(check-b) elif (location>10 and location<20): if ((check-b)>4): print ("$", end=str(32+12*((check-b)-4))) print ("0") total = total + 32+12*((check-b)-4) else: print ("$", end=str(8*(check-b))) print ("0") total = total+8*(check-b) elif (location>19 and location<30): if ((check-b)>4): print ("$", end=str(48+24*((check-b)-4))) print ("0") total = total + 48+24*((check-b)-4) else: print ("Ur doo doo, I don't know what location that is.") print ("$", end = str(total))#finally print the total amount print ("0")
#Mrs. Mae- I could also use the replace("","") function instead of split(), which I can tell makes a whole lot more sense
big_monies=0; for i in range(4): place=int(input("place:")) Time_Start=input("time start:") Time_end=input("time end:") if Time_Start=="1": Time_Start=float(9) elif Time_Start=="2": Time_Start=float(9.5) elif Time_Start=="3": Time_Start=float(10) elif Time_Start=="4": Time_Start=float(10.5) elif Time_Start=="5": Time_Start=float(11) elif Time_Start=="6": Time_Start=float(11.5) elif Time_Start=="7": Time_Start=float(12) elif Time_Start=="8": Time_Start=float(12.5) elif Time_Start=="9": Time_Start=float(13) elif Time_Start=="A": Time_Start=float(13.5) elif Time_Start=="B": Time_Start=float(14) elif Time_Start=="C": Time_Start=float(14.5) elif Time_Start=="D": Time_Start=float(15) elif Time_Start=="E": Time_Start=float(15.5) elif Time_Start=="F": Time_Start=float(16) elif Time_Start=="G": Time_Start=float(16.5) elif Time_Start=="H": Time_Start=float(17) if Time_end=="1": Time_end=float(9) elif Time_end=="2": Time_end=float(9.5) elif Time_end=="3": Time_end=float(10) elif Time_end=="4": Time_end=float(10.5) elif Time_end=="5": Time_end=float(11) elif Time_end=="6": Time_end=float(11.5) elif Time_end=="7": Time_end=float(12) elif Time_end=="8": Time_end=float(12.5) elif Time_end=="9": Time_end=float(13) elif Time_end=="A": Time_end=float(13.5) elif Time_end=="B": Time_end=float(14) elif Time_end=="C": Time_end=float(14.5) elif Time_end=="D": Time_end=float(15) elif Time_end=="E": Time_end=float(15.5) elif Time_end=="F": Time_end=float(16) elif Time_end=="G": Time_end=float(16.5) elif Time_end=="H": Time_end=float(17)
Time=Time_end-Time_Start money=0 if place-10<0: money=Time*10 if 0<place-10<10: if Time-4>0: overtime=Time-4 money=overtime*12+4*8 elif Time-4<=0: money=Time*8 if 10<place-10<20: if Time-4>0: overtime=Time-4 money=overtime*24+4*12 elif Time-4<=0: money=Time*12 big_monies=big_monies+money print(money) print(big_monies)
location = [int(input("please enter location 1:")), int(input("please enter location 2:")), int(input("please enter location 3:")), int(input("please enter location 4:"))] startTime = [input("please enter start time 1:"), input("please enter start time 2:"), input("please enter start time 3:"), input("please enter start time 4:")] endTime = [input("please enter ending time 1:"), input("please enter ending time 2:"), input("please enter ending time 3:"), input("please enter ending time 4:")] timecodes = ["1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H"] times = [9,9.5,10,10.5,11,11.5,12,12.5,13,13.5,14,14.5,15,15.5,16,16.5,17] hoursWorked = [times[timecodes.index(endTime[0])] - times[timecodes.index(startTime[0])], times[timecodes.index(endTime[1])] - times[timecodes.index(startTime[1])], times[timecodes.index(endTime[2])] - times[timecodes.index(startTime[2])], times[timecodes.index(endTime[3])] - times[timecodes.index(startTime[3])]] moneyEarned = 0; for i in range (4): if location[i] <= 9: print ('${:,.2f}'.format(hoursWorked[i] * 10.0)) moneyEarned += hoursWorked[i] * 10.0
elif location[i] <= 19: if hoursWorked[i] <= 4: print ('${:,.2f}'.format(hoursWorked[i] * 8.0)) moneyEarned += hoursWorked[i] * 8.0 else: print ('${:,.2f}'.format(32 + (hoursWorked[i] - 4) * 12.0)) moneyEarned += 32 + (hoursWorked[i] - 4) * 12.0
else: if hoursWorked[i] <= 4: print ('${:,.2f}'.format(hoursWorked[i] * 12.0)) moneyEarned += hoursWorked[i] * 12.0 else: print ('${:,.2f}'.format(48 + (hoursWorked[i] - 4)* 24.0)) moneyEarned += 48 + (hoursWorked[i] - 4)* 24.0
print('${:,.2f}'.format(moneyEarned))