Year of Python (YOP) – Week Three

19Jan15

Hello Reader!
Well this week I’m sort of taking a shortcut, but what I enjoyed about this script is it was rather easy for me to write. I’m happy about that because it at least gives me some hope that this resolution will accomplish what I want it to.

I teach Computer Forensics part time for a University here where I live. The class started up last week, and I was putting some finalizing touches on my week one lecture. Part of this lecture just goes over the fundamentals of converting decimal numbers to both their binary values and their hexadecimal values. For the students homework assignment, they have to take a binary number and write down the decimal and hex values, and then take a hexadecimal number and write down the binary and decimal numbers.

What I wanted to do is update that part of my presentation every year, but not really have to think about what numbers to put in with the homework assignment. So why not have Python generate everything for me!

Overall this is a really simple script, it starts out with a function that does all the heavy lifting:

def random_number_generator():
    ran_decimal = random.randint(1, 255)
    return (ran_decimal, bin(ran_decimal), hex(ran_decimal))

essentially this function generates a random decimal number from 1-255, and then returns the decimal value, along with the equivalent binary and hexidecimal values.

The second part of the script just takes the data from the function and writes it to a file. I wanted to write to a file instead of presenting the output to the screen, because it would be easier to copy and paste the values into my homework assignment.

The numbers_start and numbers_end values are optional for anyone else, I have them in there because the homework assignment is 40 problems.

Until next week!

https://github.com/CdtDelta/YOP

Advertisements


No Responses Yet to “Year of Python (YOP) – Week Three”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: