Forumite Members › General Topics › Tech › Makers & Builders › Programming/Code tips › Learning to program
Tagged: Android, app, program, programming
- This topic has 133 replies, 6 voices, and was last updated 7 years, 3 months ago by
Wheels-Of-Fire.
-
AuthorPosts
-
November 2, 2018 at 7:15 pm #27878
Retro would not be a bad topic addition. Most of the games I purchase are from Gog and fit into the retro category. I have all but given up on modern games as they require two or more hours of concentrated effort, and some idiot games only allow saves at points they specify.
Retro games + mods are very playable especially some of the Skyrim mods.
November 7, 2018 at 2:45 am #28029Well, I’ve just done my first bit of programming 😀
I’ve been going through a load of the Codecademy basics, so have only just started the Python course. It’s not as hard as I was expecting, so that’s a bonus. Codecademy seems to skip forward though. One of the tests used concatenation before it was introduced in a following lesson. It was confusing, but there were links to get help, so I got past it. One of the other tests used this:
exercises_completed = 13
points_per_exercise = 5
point_total = 100and told me to update the point_total to the existing point_total plus exercises_completed x points_per_exercise, but it had only shown addition and subtraction so far. I created a new variable, but was marked as wrong. I went back to the previous few pages to see what I’d missed, and when I returned to it, the exercise had marked my answer as correct, so I don’t know what their correct answer was. This was how I finished that exercise:
total = int(exercises_completed)*int(points_per_exercise)
point_total +=totalI’ve gone onto the mad libs game now, which really drums in how repetitive programming can be! It’s great though, because I’ve just ‘written’* a game 😀
Thanks again for the Codecademy links Ed 🙂
*not really written, just copied, but I’m claiming a victory 😀
November 7, 2018 at 10:06 am #28034I am not familiar with Python syntax but as they asked you to “update” point_total you probably don’t need a new variable. The syntax in BASIC would be :
point_total=point_total+(exercises_completed*points_per_exercise)
November 7, 2018 at 1:38 pm #28042The full program in C/C++ would be as below (Note the use of point_total += instead of point_total = point_total but either will work)
#include “pch.h”
#include <iostream>
using namespace std;
int main()
{
int exercises_completed = 13;
int points_per_exercise = 5;
int point_total = 100;
cout << “Old Total = ” << point_total << endl;
point_total += exercises_completed * points_per_exercise;
cout << “New Total = ” << point_total << endl;
}
November 7, 2018 at 7:37 pm #28058I just read back my last reply and it seems to be a bit negative, it was not meant to be !
Keep up the good work ?
November 7, 2018 at 7:55 pm #28060If you take a look at the CodeAcademy site the lessons move quite slowly at first which is a good idea. Imo Python is far more idiosyncratic wrt what works and what does not. Getting the syntax under your belt is a good start.
Some of the Codeacademy tips are pretty good e.g. use spaces rather than tabs as the editors sometimes get confused with tabs versus spaces. (indentation is used instead of the much saner brackets and semi colons.)
November 7, 2018 at 8:20 pm #28061I am not familiar with Python syntax but as they asked you to “update” point_total you probably don’t need a new variable. The syntax in BASIC would be : point_total=point_total+(exercises_completed*points_per_exercise)
That’s interesting, thanks 🙂 I didn’t think of brackets, and probably wouldn’t have either because they’re used elsewhere. I’ll have a play when I’m on the computer tomorrow 🙂
It’s strange to see the differences between the languages for the same task. It makes you realise that they really are languages, and it’s not just a buzzword or something daft.
I just read back my last reply and it seems to be a bit negative, it was not meant to be ! Keep up the good work
Nah, I read it as someone offering advice, which I’m grateful for 🙂
One thing that I found weird last night was saving in Notepad++. I saved some examples as .txt files just for reminders, but I saved the game as a .py file. As soon as I clicked save, the text colours changed, and things like brackets were highlighted. Daft as it might sound, it made it feel more like programming than just copying and modifying text 😀
November 7, 2018 at 8:44 pm #28063Tippon, once you have played with a few languages you will find similarities across many of them. There are unfortunately a few exceptions such as Lisp , Forth and APL (insanity personified). However, generally speaking once you are comfortable with one language it is a reasonably simple task to move to another.
November 8, 2018 at 5:53 pm #28089Yep Ed. Variables, loops, conditional branches and then array and string handling. After that its mostly language specifics and GCE maths ?
November 8, 2018 at 6:11 pm #28090Speaking of language specifics, Atari BASIC has a simple PLOT X,Y command that will put a filled in 8×8 square (CHR$ number something cant remember which) at position X,X as long as you are in character screen mode. Can’t find anything like it for a C console app.
November 8, 2018 at 6:22 pm #28092Er position X,Y obviously ?
November 8, 2018 at 7:11 pm #28093Tippon,
I find that with Python I’m always learning as there are so many different libraries to make tasks ‘easier’.
If you have Ubuntu in a VM I recommend that you follow (i/e. copy and paste) the steps in this article to get a Chrome web-driver up and running. You can use Firefox and even IE, but I recommend chrome as there is a lot of code available with Google.
Once you have this installed you will have access to Selenium a library that gives you a lot of web page manipulation.
I’ll then post a short snippet that will first bring up the BBC web site (and allow you to go through its irritating log-ons/cookie/oks etc), then save the necessary cookies and exit. I’ll also give a second short snippet that opens a fresh BBC web page and loads the cookies you previously saved..
This is a bit like having your own web page docker as other than the cookies you deliberately save all other signs of your presence are lost when the python script closes.
When you have the required libraries established Python takes very little code to do amazing things.
November 8, 2018 at 8:10 pm #28096<p style=”text-align: justify;”>Still don’t know Python but you are going to find that some of the things you thought were commands are actually calls into functions or classes that must be included to work.</p>
November 8, 2018 at 8:17 pm #28097And i still dont want the HTML formatting posts !
November 8, 2018 at 8:36 pm #28098Python Libraries are like DLLs i.e a lot of routines. procedures, functions that are bundled together. With a little bit of extra work they will also work in C.
November 9, 2018 at 2:06 pm #28119Just going to point out that a DLL is a dynamicly linked library. It is pulled in at run time.
November 9, 2018 at 2:25 pm #28120Python is INTERPRETED so everything is at run-time, including .py scripts and so-called compiled .pyc files. A pyc file is still interpreted, it just loads more quickly.
[edit] Python lets it all hang-out and allows libraries to be loaded anywhere you want as long as it is before any calling program.
November 9, 2018 at 4:34 pm #28123Ah go play with that then
November 12, 2018 at 11:15 pm #28192Well I didn’t exactly have a play but I did look up .PYC files. It looks like Python can compile libraries into an intermediate portable or P Code format to save space and speed the interpratation. Sorry to go on about the out dated Atari BASIC but it does a similar thing by tokenising every line you enter for the same reasons. If you SAVE a program to disc you get the tokenised version complete with variable table but if you use LIST “D:MYPROG.TXT” you just get an ASCII text file that you can reload with ENTER. If you use ENTER then the program gets tokenised as it is read in and merged with any program in memory (as long as the line numbers are different).
November 13, 2018 at 12:11 pm #28208Tippon,
as promised if you followed the instructions to load chromedriver or installed chromium and chromium-chromedriver using Synaptic then the following script allows you to set up an instance of chrome that can be either persistent or non-persistent. Enjoy:
##### Python script follows
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
# the starting ‘hash-bang’ #! tells the interpreter it must be Python 2.7
# the second tells it that utf-8 encoding is being use. Does not matter here, but sometimes usefulfrom selenium import webdriver
from selenium.webdriver.chrome.options import Options
# remove next two lines if debugging finished
import logging
from tkMessageBox import showinfofrom time import localtime
from time import time
from time import sleep# selenium will complain if it cannot find the chromedriver.
#The easy fix is to copy chromedriver to /usr/bin# set up logging, remove when debugged
logging.basicConfig(level=logging.DEBUG,
format='(%(threadName)-9s) %(message)s’,)# remove irritating ‘controlled by automation’ bar
# sets up selenium browser, using default path for webdriver
chrome_options = Options()
chrome_options.add_argument(“–disable-infobars”)
# if you remove the following option you get a ‘clean’ browser each time
# If just copying code first make a ‘Data’ folder in the same place as script
chrome_options.add_argument(“user-data-dir=./Data/”)
# sets browser size and position
# not all browser sizes work – depend on site being visited
chrome_options.add_argument(“–window-position=0,0”)
chrome_options.add_argument(“window-size=519,520”)# put the options in browser
browser = webdriver.Chrome(chrome_options=chrome_options)# give it a second then move browser
sleep(1)
browser.set_window_position(x=500, y=0)
sleep(0.5)logging.debug(“Loading BBC Home Page”)
browser.get(‘http://bbc.co.uk’)
browser.titlelogging.debug(“Using old cookies loaded”)
browser.title
logging.debug(“Waiting 200 ticks”)
sleep(100)# close current web page
browser.close()
# quit
browser.quit() -
AuthorPosts
- You must be logged in to reply to this topic.
