[Tutor] Hi there!
Alan Gauld
alan.gauld at yahoo.co.uk
Thu Nov 14 13:32:37 EST 2019
On 14/11/2019 18:14, Hamnah Baig wrote:
> I need to create a code that lets me save the input and output in an
> external file.
OK, it will go something like this
open input.txt and output.txt files
read input from user (or whereverit comes from)
write input to input.txt
process input data
write result to output.txt
close input.txt and output.txt
Now which parts of that are you struggling with?
Do you not know how to do any of the steps?
> I'm also struggling to make my code identify between an odd number and an
> even number and when I did create one it seemed a bit too long and I feel
> like I'm confusing myself.
The normal way to do that is to perform an integer division by 2
and check the remainder part to see if it is zero. If the remainder
is zero then the number must be even.
Python has a couple of tools to help with that. The first is the
divmod() function and the second is the modulo operator (%) which
returns the remainder part only.
If you need more help please get back to us.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list