Thanks! I did get the thing working eventually (second.py
in repo once I push it). Turned out the tutorial had a mistake in it! Tried to use input
to read user input, but the right one was raw_input
.
oh, that’s indeed frustrating.
well, a new day brings new luck
Don’t overdo it day 1… You need to have steam in the engine for 30 more days.
if num == int:
print("Was your number", num)
else:
print("Please try again")
I don’t think you can directly compare the variable to a type. You should be able to do this:
if type(num) == int:
print("Was your number", num)
else:
print("Please try again")
Thanks! I’ll take a look into those resources.
@anon54210716 yeah that piece of code came straight from my head after reading tutorials for 30min. Just wanted to test out how variables work in python, and weeell it was not as simple as I thought. Decided to just bite the bullet and follow the tutorials bit longer before going all out.
Are you building the scripts and executing them? It can be handy typing stuff directly into python command line, like this, to test stuff out:
I write the scripts with Vim and then just execute them with python blabla.py
I noticed that stuff can be typed directly to python compiler or prompt or, idk. But yea for some reason it didn’t occur to me to type commands and test things out that way. I might as well do that! Thanks!
Day 2
Didn’t do any actual coding, at least not yet. I spent the time reading tutorials and figuring and testing stuff out. There’s still couple hours left for this evening so let’s see if I get some stuff done.
It’s an hour a day you know
Yeah, but I didn’t use an hour today. Yet.
Day 3
Ok, I learned something new today and figured out why there seems to be so much contradiction between different tutorials. Answer is differences between python versions 2 and 3. I knew there are two different versions, and that for example Ubuntu has both 2 and 3 installed, probably to ensure compatibility between older and newer python scripts. If I’m wrong on this one or any other thing I say here please feel free to correct me!
I initially thought version 2 and 3 would be compatible with each other, version 3 just adding more stuff to previous version, but I was wrong. A simple print
command works diffenently in python 2 and 3. Version 2 does not need parenthesis for printed objects but version 3 does:
-
print (123)
works in both versions -
print 123
works only in python2
I found out this problem after I wondered why the tutorial examples are not working in my online compiler (link bellow), but then I tested those examples at home in linux terminal, and python3 was ḱind enough to actually tell me what’s wrong:
I usually have some down time at work, during lunch break and so on. So I fired up google and tried to find online python compilers that are not blocked by the company firewall. I found these and especially the OnlineGDB looks really nice, since you can write short scripts with it. It is slow, but for testing things out I don’t think it’s that bad. Note the OnlineGDB only supports python3.
https://www.onlinegdb.com/online_python_compiler
Now question to the actual programmers: Should I prioritize to python2 or 3? My own guess is python3 should be better option, since it is newer and likely to be supported longer. Like who knows when python2 will get removed and deprecated? But idk. I might be completely wrong on this one…
Anyway, no meaningful code to share today. Just wanted to share this so that others won’t get stuck because of this.
Tomorrow I might have a busy day, so lets see if I have enough time for tomorrow to work on this.
yep, you are exactly right. There is a pretty significant break between 2 and 3 unfortunately, but it was necessary. I’m sorry you ran into this issue.
I’m not an actual programmer but I would definitely recommend to use python 3. Consider python 2 as deprecated. Yes you will always be able to run Python 2 code on its own but interfacing between python 2 and three is more painful than I would like to admit. Also there are great features in Python 3 that you would be missing in the long run and you don’t have legacy code to support yet (I’m guessing). Just my 2 cents and happy coding!
Day 4
Well, unfortunately I don’t have any code to show again, but I’ve spent the hour (and little extra) watching this video tutorial (thanks @anon43365633 for sharing this!) and reading the python tutorial from Tutorialspoint. I didn’t like it at first, but now that I have banged my head with some basic stuff it looks more accessible. Plan for tomorrow is to finish that video tutorial.
Part of the reason why I don’t have any real code to share is because I currently use the python prompt directly, as suggested by @anon54210716. I don’t see any reason why write and compile/execute these small scripts since using the python prompt is much faster for this purpose.
I’ll think in addition to that video tutorial, I could also try to get that second.py
in my repo to work.
EDIT: and as @anotherriddle suggested I’ll focus on python 3 from now.
Day 5
Finished the video tutorial from Derek Banas. About last 15 minutes made me to rewind and look things up again, and objects where something I didn’t fully grasp, yet. I remember it took me a while to wrap my head around classes and objects in Java, so I’ll try and test some examples tomorrow and see if that helps. I have a feeling this is something that requires trial and error before making sense.
But hey, tomorrow is national holiday and I have nothing special planned, so I should have plenty of time to figure things out. I even cleaned the house today so that I don’t have to waste time such mundane things tomorrow.
Day 6
Well today was “fun with lists”. Created new test1.py
file to repo, which will (again) be used for just some random testing. I didn’t get to try out modules yet, but I did read some documentation about the topic.
I’m little confused about lists and tuples. I understand that both work more or less the same way, but tuples can’t be changed. I tried to find some practical examples for situations where tuples are better option to use than lists, but didn’t find any good examples yet. I’ll do some research tomorrow.
Oh, and I did install PyCharm and decided to use it for now. I’m not going to abandon Vim, but PyCharm and other IDEs have features available by default which will require configuring in Vim, and that’s something I don’t want to use my time right now. So I rather prioritize, and keep Python in my focus atm. I might try to configure Vim during the next weekend, but we will see.
Tuples are a construct originating from mathematics. It is a further abstraction of an iterable List. The main reason why the differentiation in Python exists is probably because the language is used a lot in Mathematics, Physics and data science but I believe it also exists in Haskell.
The main distinction for practical purposes is indeed that tuples are immutable objects like you mentioned. Using it makes sense if you want to be sure that the “length” of your record or vector does not change which is important for certain mathematical operations. With a list you can always append, prepend, drop or add values. This is a distinct feature of the list. You could also use lists for tuples but the “feature” of the tuple is what it can not do.
I’m not that good with explaining. I hope this makes things a bit clearer.
HA! Math! My dear old enemy. You cannot hide from me, no matter what form you chose to wear!
Thanks! That actually clarified a lot of things! I thought at first why not just protect lists some how, but your explanation gave good point why sometimes it’s good to be extra cautious. I mean, someone at NASA might be little pissed if mars lander crashed to surface just because somebody forgot to write protect crucial list in python script.
although NASA probably uses something else to calculate flight data than python…
and you would be right about that. MSL runs on C .
Although you would be surprised at the places where python is used. (Hell, I am constantly surprised.) It would be equally bad if the interplanetary probe misses it’s target because the gravity assist was calculated wrong.
I can feel ya. I almost failed school at one point because I am bad at maths. Today I am still bad at maths but on a bit of a different level.
Think of maths as an impressive multitool. In many cases you aren’t even aware you are using it and it still works but the great thing is: Mathematics has the most comprehensive and precise documentation of anything in the world. It’s just a bit hard to read at times.
You could consider using ‘Microsoft Code’ as an editor.
I know the first word is poison. But, its open source and works pretty well with Python.
Thanks! I’ve heard good things about that editor. I installed pycharm first and it seems to do what I need for now. I will take a look at VS Code later, but right now I’ll keep my focus on learning python.