Python Forum
What am I doing wrong?
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What am I doing wrong?
#3
The first thing your are doing wrong is not telling us what error you are getting, or how the program is not working.

The lines variable is going to be a list of strings. That's how files are read in. You need to convert those to integers with the int() function. Then, you have a parameter to your leapYear function, but you are not supplying a parameter to it when you call it in appendFile. You need to supply the integer year to leapYear so it knows what year to calculate on. Next, leapYear is not returning anything explicity. That means it implicitly returns None, which evaluates to False, so if leapYear(): will always be false. You need to return the value you are calculating in leapYear. Just put a return statement before the calculation and that will work. Finally, when leapYear() is True, you want to write it to a file. At which point I realize you've named your file 'file', which is a bad idea because file is a keyword in Python. So rename those files something like all_file and leap_file. Then to write to the file, you use the write method of the file. You can just write the line you read: leap_file.write(line).

In previous posts you made, it seemed that the input file had lines that weren't years and lines that had years and other text. If that is the case, get this program working with a dummy file that is just years, and then you can worry about the full file.

I would suggest checking out a functions tutorial. There should be a link to one in my signature below.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
What am I doing wrong? - by forumer444 - Sep-15-2017, 08:39 PM
RE: What am I doing wrong? - by Larz60+ - Sep-15-2017, 09:01 PM
RE: What am I doing wrong? - by ichabod801 - Sep-15-2017, 09:01 PM
RE: What am I doing wrong? - by forumer444 - Sep-15-2017, 09:32 PM
RE: What am I doing wrong? - by ichabod801 - Sep-15-2017, 09:04 PM
RE: What am I doing wrong? - by nilamo - Sep-15-2017, 09:30 PM
RE: What am I doing wrong? - by ichabod801 - Sep-15-2017, 10:59 PM
RE: What am I doing wrong? - by forumer444 - Sep-16-2017, 03:24 AM
RE: What am I doing wrong? - by ichabod801 - Sep-16-2017, 01:24 PM
RE: What am I doing wrong? - by forumer444 - Sep-16-2017, 10:09 PM
RE: What am I doing wrong? - by ichabod801 - Sep-17-2017, 01:27 AM
RE: What am I doing wrong? - by forumer444 - Sep-17-2017, 11:01 PM
RE: What am I doing wrong? - by ichabod801 - Sep-18-2017, 03:21 AM
RE: What am I doing wrong? - by forumer444 - Sep-20-2017, 12:47 AM
RE: What am I doing wrong? - by ichabod801 - Sep-20-2017, 01:24 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020