The Student Room Group

FREE Programming/Coding Help Desk

Scroll to see replies

Reply 780
Original post by winterscoming
Main method (sometimes is also known as the "entry point" for the program): https://docs.oracle.com/javase/tutorial/getStarted/application/index.html#MAIN

JUnit: https://junit.org/junit4/faq.html

You're too pure for this world, I would have told him to Google it.
Hi would like some help with this code
I have tried to make a list comprehension out of the lines;

import string
def getAvailableLetters(lettersGuessed): '''
for char in listAlphabet[:]:
if char in lettersGuessed:
del(listAlphabet[listAlphabet.index(char)])


how do i transform the both for loop into list comprehension like the one below
The problem is that I tried the one below but it is not work .

Please help
lst = [del (listAlphabet[listAlphabet.index(char)) if char in lettersGuessed for char in listAlphabet[:]]


lettersGuessed =['e', 'i', 'k', 'p', 'r', 's']
print(getAvailableLetters(lettersGuessed))

import string
def getAvailableLetters(lettersGuessed):
'''lettersGuessed: list, what letters have been guessed so far returns: string,
comprised of letters that represents what letters have not yet been guessed. '''
# FILL IN YOUR CODE HERE...
alphabet = (string.ascii_lowercase)
print(alphabet)
listAlphabet = list(alphabet)
print(listAlphabet)

''' how do i make lines 17 to 19 into a list comprehension'''
for char in listAlphabet[:]:
if char in lettersGuessed:
del(listAlphabet[listAlphabet.index(char)])

lst = [del (listAlphabet[listAlphabet.index(char)) if char in lettersGuessed for char in listAlphabet[:]]
return (''.join(listAlphabet))
lettersGuessed = ['e', 'i', 'k', 'p', 'r', 's']
print(getAvailableLetters(lettersGuessed))
(edited 4 years ago)
Original post by bigmansouf
Hi would like some help with this code
I have tried to make a list comprehension out of the lines;


import string
def getAvailableLetters(lettersGuessed):
for char in listAlphabet[:]:
if char in lettersGuessed:
del(listAlphabet[listAlphabet.index(char)])


how do i transform the both for loop into list comprehension like the one below
The problem is that I tried the one below but it is not work .

Please help

lst = [del (listAlphabet[listAlphabet.index(char)) if char in lettersGuessed for char in listAlphabet[:]]



You're almost right, except that your for and if statements are the wrong way around. List comprehension syntax should put the if afterwards.

e.g. https://repl.it/repls/KosherExtraneousFunnel

my_list = [1,2,3,4,5,6]
foo = [str(x)]
print(' '.join(foo))



Incidentally, I'm not quite sure what your list comprehension is intended to do, but it looks like you're modifying the existing list - it would seem much simpler just to create a new list using not in instead:
i.e. https://repl.it/repls/SeriousEmptyLanservers

listAlphabet = "abcdefghijklmnopqrstuvwxyz"
lettersGuessed = "fmqepb"
lst = [char for char in listAlphabet if char not in lettersGuessed]
print(' '.join(lst))
(edited 4 years ago)
Original post by winterscoming
Firstly by sticking to one at-a-time. People tend not to switch between programming languages and frameworks very often, and I'd say it's not really useful to learn lots of languages or frameworks because people tend to be more valuable when they can claim a lot of expertise and in-depth knowledge on a small handful of technologies.

Also, Vue.js is a client-side framework, whereas Laravel is server-side. You're probably going to find it much easier if you ditch Vuejs for now and maybe come back to it in 6 months once you're already comfortable with the server-side framework.

Server-side frameworks are pretty much essential because any web app you build really needs something to build the back end logic with. Client-side frameworks like Vue are nice-to-have but far less important. Remember that your server is where the 'real' work needs to happen - e.g. connecting to databases, handling user logins, processing the core app logic, etc. Lots of people still write web apps without much dynamic behaviour on the client side.

A client-side framework exists to help you write a better UI for the app without using loads of hacky JavaScript and code which hooks into the browser's document API, but you can still write perfectly good web apps using static HTML as well. Don't forget that there's stuff like Bootstrap which can help you make a lot of really neat looking apps by using those Bootstrap CSS classes, and without needing much/any JavaScript.

However, if you did decide to learn another client-side framework after VueJS, you'd probably find that both React and Angular are a much gentler learning curve because a lot of the tools, concepts, terminology and patterns should be familiar.


Node JS is a JavaScript runtime (i.e. allows JavaScript to be run on a server just like Python or PHP). It has got an HTTP module which means you can write some JavaScript and use that as a web server to listen to HTTP requests and serve up web content, although you'd either have to write that script yourself or install a package which contains a webserver script that runs in Node.JS.

However, people more commonly use to run a local 'development' web server which is useful when trying to develop an app in Vue/Angular/React. Those 3 frameworks are all bundled with scripts that use the Node.JS HTTP module to run development web servers, so that you can easily test your Vue/Angular/React app just by typing "npm start" on the commandline. The main reason that node.js appears everywhere is that anyone creating an app with Vue, Angular or React will be using node.js for testing their app.

XAMP is a bundle of several different bits of software, so it's not quite the same. XAMP is mainly Apache (web server), MariaDB (database) and PHP (Runtime), so it's not quite the same. NodeJS itself equivalent to the PHP runtime or the Python runtime.

Some people do use Node.JS it for their Live web services since it means they're able to write JavaScript on the front-end and the back-end, and there's nothing inherently wrong with that, but other languages like PHP, Python and C# are also just as widely used for live/production web services.

thx for the reply. repped.


abit more if you dont mind...

1. A friend told me that i dont need to learn both web dev and software dev both. I just need to learn web dev and electron. Whats your opinion on electron ? Can electron really replace software dev programming language?



2. What kind of projects should i pursue in my portfolio? I have a few ideas but i just look up the internet and i realise there are literally hundreds of people who already have thought of that and already done it. If i do those others might think that i plagiarise others, its hard not to have similar codes when there are so many people doing the same thing. Should i use third party dependencies in my projects ? The website i create will look much better if i use bootstrap but i am worried that it might not be seen as genuine by prospectus employer as i didnt code it from the ground up.



3. I created a notepad project but i realise i cant insert ' character into the SQL database because it would upset the SQL query by fooling it into thinking the ' is the closing for the SQL statement (hence making the statement having 3 ' and hence error). How do i overcome this? Should i replace all ' and " character into keycodes like CHAR (keycode) ?



4. When i upload my project to my github how do i upload the database? Do i just upload the .sql SQL dump file?
(edited 4 years ago)
Original post by winterscoming
You're almost right, except that your for and if statements are the wrong way around. List comprehension syntax should put the if afterwards.

e.g. https://repl.it/repls/KosherExtraneousFunnel

my_list = [1,2,3,4,5,6]
foo = [str(x)]
print(' '.join(foo))



Incidentally, I'm not quite sure what your list comprehension is intended to do, but it looks like you're modifying the existing list - it would seem much simpler just to create a new list using not in instead:
i.e. https://repl.it/repls/SeriousEmptyLanservers

listAlphabet = "abcdefghijklmnopqrstuvwxyz"
lettersGuessed = "fmqepb"
lst = [char for char in listAlphabet if char not in lettersGuessed]
print(' '.join(lst))


thank you very much
Original post by HucktheForde
thx for the reply. repped.


abit more if you dont mind...

1. A friend told me that i dont need to learn both web dev and software dev both. I just need to learn web dev and electron. Whats your opinion on electron ? Can electron really replace software dev programming language?


I'm afraid it's not quite that simple unfortunately! Electron is a really cool technology, but it's still just a tool, and (like most tools) is mostly designed to solve just one type of problem. In the case of Electron, the problems it solves are all about portability of UI apps between different operating systems and devices - it's a modified version of Chromium, Google's web browser engine, whose purpose is to make it possible to build Desktop UI apps using web technologies.

Portability is obviously a very useful problem to solve, but there's a lot more to software engineering aside from just needing to support different devices/OS's. For example, there'll still always be the matter of how to build complicated business logic/rules, and work with databases or APIs, or build processes that run on a server or in the cloud, handling large volumes of traffic/data, building networked systems, making the app and data secure, etc.

New tools appear all the time, and new technologies are always being created, but also new problems are being discovered all the time, or existing problems become more complicated (e.g. Security is a constant game of "cat and mouse" between criminals and IT professionals). Portability used to be a hugely difficult and expensive problem about 10 years ago, but in 2019 it can already be done far more easily and cheaply using web technologies and tools like Electron. People still spend a lot of money solving other big/difficult problems instead.

Also, while people frequently build news tool like Electron, it's uncommon for anything new to actually replace old/existing tools - when a new technology arrives, people carry on using whatever they were using before, with many technologies often hanging around for decades. You'll obviously find new projects starting up using new tools, especially with new companies or new teams, but existing teams/companies, existing projects, etc will usually stick to the stuff they already use and they usually won't put in the time/money/effort re-writing their system every time someone invents a new/different way of doing things.

I'm not sure there's any need to make a big distinction between "web dev" and "software dev" anyway, because web development is software development using web technologies (just as 'database development' is software development using SQL-based technologies, and 'Game development' is software development using gaming technologies, etc). Software development still boils down to analytical skills, problem solving, computational thinking, etc. so it's still important to master those skills as a web developer or database developer, etc.


Original post by HucktheForde

2. What kind of projects should i pursue in my portfolio? I have a few ideas but i just look up the internet and i realise there are literally hundreds of people who already have thought of that and already done it. If i do those others might think that i plagiarise others, its hard not to have similar codes when there are so many people doing the same thing.
Don't worry about that! Facebook wasn't an original idea, Chrome wasn't an original idea, WhatsApp wasn't an original idea, TSR wasn't an original idea, etc. Nearly all software is based on ideas which had already been done before, but often it's down to the implementation and the small details and particular features or (as well as whether the software works well, is reliable, has no bugs, a good UI, etc) about whether people actually use it or not.

On code similarity, that's actually very unlikely for anything more than a very tiny app/problem. Most real-world problems are usually so much larger and more open-ended in the space between the problem and the solution, so people also tend to bring a lot of their own style and ways of thinking to the problem as well as the code they write and the way they think about designing it. You could put almost any open-ended problem to 10 different programmers, then you will most likely get 10 very different solutions.

Once you start wandering into larger, non-trivial apps (e.g. thousands of lines of code which might take you a several hundred hours to build) then the whole shape and structure of the app will very much depend on alot of decisions you make - e.g. how you structure your data in the DB, how you split up the UI and its workflow, how you break the code into different classes/functions, which memory data structures you use, which tools/frameworks you use, whether you end up following any particular styles or patterns, etc.


Original post by HucktheForde

Should i use third party dependencies in my projects ? The website i create will look much better if i use bootstrap but i am worried that it might not be seen as genuine by prospectus employer as i didnt code it from the ground up.
Yes, using well-known and popular dependencies/frameworks/libraries is a really good idea because you'll probably find most of the jobs out there will be looking for people who have used them or something similar to them before.

Bootstrap is a good choice because it's used everywhere and quite quick/easy to learn. It's highly likely that any company you join which builds web apps is probably already using Bootstrap or something very similar to it so that's a good thing to have on your CV and portfolio. Generally speaking it's good and encouraged to use 3rd-party libraries/frameworks if they are actually helpful for the kind of software you're writing. Those frameworks should all help you make bigger, better, and more interesting apps which can shows your ability to build the kind of larger projects that you might end up working with in those jobs.

Also remember that just because you use Bootstrap doesn't mean you won't end up needing to write your own CSS for some things if you want to start tweaking the appearance of stuff. Same with any other kind of framework really, you might use it to get the overall structure of the app, and that might get you 80% of the way to a working app, but there'll always be another 20% somewhere (which takes a lot longer since you're coding those bits yourself from scratch) which covers stuff that the framework still doesn't do for you, or which doesn't quite work in the way you want.


Original post by HucktheForde

3. I created a notepad project but i realise i cant insert ' character into the SQL database because it would upset the SQL query by fooling it into thinking the ' is the closing for the SQL statement (hence making the statement having 3 ' and hence error). How do i overcome this? Should i replace all ' and " character into keycodes like CHAR (keycode) ?

Which programming language and database library did you write that with? The safe, simple, secure way to fix this is to use parameterised SQL statements. (sometimes known as prepared statements or parameterised queries).

Each item of data that you're trying to insert into the query would be represented as a 'parameter' in the SQL statement (The parameter would appear in the SQL statement itself as either a named variable such as @myVariable or just a wildcard character such as ?). Then you'd use whichever language/library you're running the SQL with to provide the SQL separately from the data. (Whatever language/library you're using to connect to the SQL database will almost certainly have a way to do this).



Original post by HucktheForde

4. When i upload my project to my github how do i upload the database? Do i just upload the .sql SQL dump file?

Yes that's fine, and is a fairly normal way to store your database in Git.
I @Async,
I am developing an app to android and app, which purpose is get directions to a certain clicked marker (point) in the map.
So, I am using the Google Maps API with node.js, and I have the data from the points stored in a MongoDB.
I've been serching but I can't find anything that solves what I want to do.

I want now to get those points coordinates from the data base object and then use the coordinates to when I click a marker (a point), then appears a infowindow with a button saying "go to location" and when I click this button I will have the directions from the point where I am(or where any other user is like, a current location) to the clicked marker. I don't know if I explained myself clearly, but let me know.

If you could help, that would be great, I am in a bit of a hurry with this because I have a deadline and I am a little bit new to Node.js.
(edited 4 years ago)
Original post by ne_chan
I @Async,
I am developing an app to android and app, which purpose is get directions to a certain clicked marker (point) in the map.
So, I am using the Google Maps API with node.js, and I have the data from the points stored in a MongoDB.
I've been serching but I can't find anything that solves what I want to do.

I want now to get those points coordinates from the data base object and then use the coordinates to when I click a marker (a point), then appears a infowindow with a button saying "go to location" and when I click this button I will have the directions from the point where I am(or where any other user is like, a current location) to the clicked marker. I don't know if I explained myself clearly, but let me know.

If you could help, that would be great, I am in a bit of a hurry with this because I have a deadline and I am a little bit new to Node.js.

Can anyone help?
i need help in my a level computer science programming project
Original post by nicky121student
i need help in my a level computer science programming project

can anyone help me..plzzzzz
can any1 hep me wih this plssss...
have to submit it tommorrow...
i cant think of what to do...what to start with....nd what not to...
0
i went to a job interview and they asked me one question i cant answer. They asked me if i understand the concept of recursive. I said no.

I went home and started googling. So this is what it is

https://en.wikipedia.org/wiki/Recursion_(computer_science)

i read, and still didnt understand. It sounds like its something to do with looping. Well if its all about looping and iteration i sure do understand and should have said yes.

Can you please assist to explain recursion from a more layman approach?
Original post by HucktheForde
i went to a job interview and they asked me one question i cant answer. They asked me if i understand the concept of recursive. I said no.

I went home and started googling. So this is what it is

https://en.wikipedia.org/wiki/Recursion_(computer_science)

i read, and still didnt understand. It sounds like its something to do with looping. Well if its all about looping and iteration i sure do understand and should have said yes.

Can you please assist to explain recursion from a more layman approach?


Recursion is a different kind of looping compared with Iteration. Iteration could be considered as a way of writing structured code which is compiled down into "GOTO" statements - e.g. a plain old While loop is iterative since all it does is 'jump' back to the beginning of the loop like this:

WHILE statement:

x = 3
WHILE x < 3 DO
PRINT x
x = x + 1
END WHILE
PRINT x

Could be translated into this using a GOTO (jump) statements:
x = 3

LABEL: "BEGIN_WHILE"
IF x < 3 THEN
PRINT x
x = x + 1
GOTO "BEGIN_WHILE"
PRINT x

(In fact, any FOR, or WHILE loop can always be translated directly into a GOTO loop because that's what compilers and interpreters do when they're turning for/while constructs into machine code)


Recursion is different because you can't represent it with a GOTO since it involves a function calling itself. For example, here's a simple bit of Python code for calculating numbers in the fibonacci sequence: (i.e. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc)
https://repl.it/repls/ForcefulSuburbanComputergraphics
def fibonacci(n):
if n == 0 or n == 1:
return 1
else:
return fibonacci(n-2) + fibonacci(n-1)

print(fibonacci(5))

The program initially calls the function fibonacci(5). (i.e. to calculate the 5th number in the fibonacci sequence which is 8).

However, the rules of the fibonacci sequence are that the 5th number is equal to the 3rd number plus the 4th number.
So to calculate the 5th fibonacci number, the program needs to call fibonacci(3) + fibonacci(4).

However, the 4th number is equal to the 3rd number plus the 4th number
And the 3rd number is equal to the 2rd number plus the 3rd number
So to calculate the 4th fibonacci number the program needs to call fibonacci(2) + fibonacci(3).
And to calculate the 3rd fibonacci number the program needs to call fibonacci(1) + fibonacci(2).
etc..

This recursive program could be rewritten by "un-rolling" the recursion into different functions where each number of the fibonacci sequence has its own function, so that you can effectively see what's happening with each function call - i.e. https://repl.it/repls/UsefulGoldWeb
def fibonacci0():
return 1 # The first number in the sequence is always 1

def fibonacci1():
return 1 # the second number in the sequence is always 1

def fibonacci2():
return fibonacci0() + fibonacci1()

def fibonacci3():
return fibonacci1() + fibonacci2()

def fibonacci4():
return fibonacci2() + fibonacci3()

def fibonacci5():
return fibonacci3() + fibonacci4()

print(fibonacci5())

This non-recursive program provides exactly the same output as the program which uses recursion; that much probably shouldn't be a surprise. What might be more of a surprise is that the control flow of the 2nd program would look exactly the same as the first program, because it's a rough illustration of how recursion works by showing the flow by "unrolling" it into multiple functions; the flow of the 2nd non-recursive program should be much easier to visualise.


One thing to remember is that functions work by using a mechanism called a Call Stack - https://en.wikipedia.org/wiki/Call_stack - This fact is absolutely vital to understanding how and why recursion works and why recursion is not the same as iteration (goto).

Every time a program calls a function, a new "frame" is created on the call stack to allocate space for its variables. However, iteration/goto does not do this. So what's really happening with recursion is that each time the fibonacci(n) function calls itself, a fresh new copy of the variable 'n' with its own value is added into the call stack.

(Plain old iterative loops are not capable of creating frames since GOTO merely changes the program's "current instruction" - an iterative loop/GOTO does not affect the structure of memory at all, so if you used a variable within an iterative loop, it would just keep using that same variable in memory)


So for Recursion, when the program calls the function fibonacci(5), a new frame on the call stack is created with n=5.
But fibonacci(5) itself calls fibonacci(4), so the existing frame will remain on the stack with n=5 and a new frame with n=4 will be created at the top.
Then fibonacci(4) calls fibonacci(3), so both existing frames with n=5 and n=4 will remain on the stack, and a new frame with n=3 will be created at the top, ad infinitum until they reach fibonacci(1) or fibonacci(0) which do no further recursion and just return a value of 1.

So then as the stack "un winds", you end up with:

fibonacci(2) returns the result of fibonacci(0)+fibonacci(1) which is 1+1=2.

fibonacci(3) returns the result of fibonacci(1)+fibonacci(2) which is 1+2=3.

fibonacci(4) returns the result of fibonacci(2)+fibonacci(3) which is 2+3=5.

fibonacci(5) returns the result of fibonacci(3)+fibonacci(4) which is 3+5=8.



This leaves the question of "What happens if I try to recursively loop 100-billion times"? -- If you were to write a plain iterative (Goto) loop which repeated itself 100-billion times, then it'd work, but would probably just take a while.

Recursion is limited because every time a function calls itself, it allocates a new frame on the stack (in memory), which stays there until that 'frame' is finished.
Memory has a finite size, therefore the stack itself is also inherently limited in size. Which means if you attempt "deep" recursion which needs 100-billion stack frames then you would eventually run out of memory on the stack; the program would "overflow" the stack, more commonly known as a Stack Overflow.
(edited 4 years ago)
Hello, I need help with ASP.Net MVC. Need to fetch keywords from the wordfile using Gembox dll and then dynamically replace the keywords with values using Stored Procedure
Original post by Shubhamk751
Hello, I need help with ASP.Net MVC. Need to fetch keywords from the wordfile using Gembox dll and then dynamically replace the keywords with values using Stored Procedure


I'd start out by building a prototype program to test out some ideas with GemBox on its own using a plain C# console app first! :smile:

The console app can be like your sandbox to write code to solve your word file problems - like testing how to read the text from the word file, trying out some stand-alone code which can find/replace words (Regex might be useful, or even just String.Replace).

If you can solve that problem on its own, then you can lift the code into your ASP.NET MVC project later once you've done all the GemBox tasks.

Even better, you could create a C# Class Library project in your Visual Studio solution (.sln) for the GemBox code, then that Class Library could be used by both the ASP.NET MVC project as well as having a Console project to develop and test it with by itself. It's a good habit to keep "back end" logic like this separated away from "Action" methods in your Controller classes. Controllers can use classes and methods from the Library project

Try this example on their website - https://www.gemboxsoftware.com/document/examples/c-sharp-vb-net-open-read-word-file/301


The C# language doesn't have 'Stored Procedures', since that's a SQL database term (meaning a SQL procedure stored in a SQL database), so I don't know what you mean by that, unless you also need to do something related to SQL as well?
Hi I am trying to write a method printCostTable() that prints out a table and takes four int arguments representing the width and length of the carpet, a start price and an end price. It should print the price, carpet cost and fitting cost for each price starting from startPrice and increasing in increments of £4, up to but not exceeding endPrice.eg:tongue:ricecarpetfitting5.0 150.0 120.09.0 270.0 120.0I am struggling and have no clue how to start. Its an activity I came across during my coding course. Many Thanks
hy ya i m not that experienced in programing and struggled to my GCSE project and m unfortunately not able to do my a level project ....but still have not given up m asking for help and at the end probubly ll b fortunate to make one ....but if i had skills i would always go for the risks and take a step forword ....even whwn i don hav them i m confident enough
What coding language???
Sorry to disappoint you, but I haven't used Java for such a long time, so I doubt I can give you a quick solution for it today. I would recommend you to start a thread for this
This one, or other ones such as Stackoverflow or Github

Quick Reply

Latest

Trending

Trending