Jump to content

Simple fun with python


Recommended Posts

Here is something fun I did messing with my computer with the low level of experience and knowledge that I have. I have had some experience with python before, but I never built anything cool with it. I had several years of not doing anything with it so I decided to start from the beginning again.

This little bit of code is basically my own personal "Hello World" program:

x = [some number]

while x > -1:

    print(x)

    x -= 1

 

The first time I encountered a "Hello World" program it took me a while to understand why it was special. It seemed like I had done more work than the computer had and I didn't value what was going on. But when I first encountered a loop and could command my machine to do actual work; that seemed cool and interesting to me. My first encounter with a loop really fired up my imagination about the power of what I was learning.

Below is a little adaptation of the code above which accepts a number defined by the user then counts down. An easy improvement would be some error handling but I was just building it to see what it would do to my machine. I recently was able to research and build my own machine. It isn't top of the line by any stretch, but it is far better than the old 2007 dell machine I had been using before. I still need to do some work to get the ram working up to specifications, and maybe try a mild over-clock but I have that on the back-burner for now.

You may notice by the layout I am running a Linux distro. I am running a duel boot Ubuntu and Windows on my machine. I boot into Ubuntu for learning and work. I only have Windows to play games with really.

This first screen is the "at rest" version which really isn't at full rest because I have Spotify and a few mild programs running still, but it is close enough for my purposes. I think the network spikes are due to Spotify reaching out to the web for adds and music.

You can see the code in the file I am using on the bottom left. The top left is the terminal I am using to run the program. You can see I already ran a few mild tests.

 

at_rest.thumb.png.fa0f359045e7d843fc7572af679ad086.png

 

 

 

Edited by JonDoh
  • Like 1
Link to comment
Share on other sites

Now for something more interesting. Using this small program I asked my computer to count down from 10 million. I wanted to see how it would interact with my CPU cores. The CPU I have is a Ryzen 7 1700 so it is in fact 8 cores with 16 threads. It looks like Ubuntu sees every thread as a separate core.

I didn't really know what to expect to see but it wasn't this. I find it interesting the different ways my cores are participating with running this simple program. I would be interested in knowing more about what is going on but of course that could be a rabbit hole I don't really need to understand.

counting10mil.thumb.png.4e4ce125d82289c41e463c7b04b9f33f.png

Edited by JonDoh
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...