Jump to content

A simple attempt at python code


G+_Nevrin O
 Share

Recommended Posts

Hi Nevrin O . You're making a great start. I think you can get rid of the call to raw_input on line 5, since it's already being called for as long as you don't have a valid input, in the while loop after it. You'll have to restructure your loop a bit though.

 

Here's a version with some possible improvements:https://gist.github.com/anonymous/10212902

 

You'll probably also notice that your program crashes when you enter something that isn't an int. I haven't seen the episode about python yet, but I think you haven't yet encountered exceptions. If you want to get a head start on learning python, you should find out more about these, they're really useful for catching all sorts of cases that can cause problems in your programs.

Link to comment
Share on other sites

Frederik Creemers Thanks for the advice on the first part of my code I was looking at a way to improve that when i saw your post. and yes i know it crashes when a non int is entered. I originally had some try/exception code in there but had issues with it so i removed it just to get further into my code. I do have experience with exceptions with c#, C++, and java but this is the first I've used them in python so im sure its just a small change that keeps breaking it. gonna post my updated version soon Thanks!

Link to comment
Share on other sites

 Share

×
×
  • Create New...