Hey guys.
I'm new to Python. I kinda blundered into a CIS major at the university I attend, and I have to say, I haven't enjoyed the Python class so far. It's so... esoteric. I'm having a TON of trouble grasping what the rest of my class view as simple concepts. I read and re-read the chapters, I attend tutoring almost every day, and still this stuff isn't clicking. I'm about halfway through the semester, and I'm really starting to panic. My scholarship (and continued pursuit of higher education) is riding on me passing this Python class. I need all the help I can get, so I'm turning to the good folks of DaniWeb for a little bit of extra-extracurricular help.
My professor has assigned a problem from our textbook for us to work out. It seems like it should be simple enough-- we have to code a program that asks for the name of a .txt file from the user (the .txt file is created by the student) that contains a few lines of text and integers. Our coded program is to read that file, do a few basic computations with the integers, and then print the output in a tabular format. The integers represent hourly rates of pay and hours worked for employees at a fictitious company. I think I've got a basic working algorithm set up, which goes as follows:
create text file
open text file in python
read file (using for loop?)
check number of hours to see if the employee worked overtime (OT)
computations
-for employee with no OT
- hourly wage * hours worked
-for employee with OT
- for the first 40 hours
- hourly wage * hours worked
- for any time after
- hourly wage * 1.5 * OT hours
print name, number hours worked and salary for each employee
Assuming that algorithm would actually work, I've also started on the code:
inName = raw_input("Enter the name of the input file: ")
inputFile = open(inName, 'r')
for line in inputFile:
wordlist = line.split()
for word in wordlist:
number = int(word)
if number <= 40:
...and then I hit a roadblock. Based on what I've read from the chapter we're currently discussing, I think two for loops would be the best way to handle this problem, but I'm completely unsure of how to proceed. The area that I've colored red is basically my "guess"-- nearly everything else is straight from the book. My tutors (who are graduate students that haven't taken any python class, but have plenty of experience with C++/Java) were as helpful as they could be, but that's not saying much. They basically told me to hit the web... so here I am. I humbly ask for ANY assistance, and I thank anyone who takes the time to help me in advance. Am I even on the right track here?