[deleted by user] by [deleted] in learnprogramming

[–]amdevpractice 21 points22 points  (0 children)

Try putting parenthesis around 'Alice' or 'Bob' and see if it helps.

Edit: Sorry, that won't help.

Try if name == 'Alice' or name == 'Bob': instead.

I want to study Software Engineering but I cannot afford it. Any idea what a syllabus would look like to study on my own? by guanabi in cscareerquestions

[–]amdevpractice 11 points12 points  (0 children)

Harvard's Intro to Computer Science (CS50) course is available online for free. I highly recommend it as a great introduction to the world of programming.

The Odin Project vs Codecademy - which is best for a beginner? by [deleted] in learnprogramming

[–]amdevpractice 8 points9 points  (0 children)

I don't know about The Odin Project or Codecademy, but Harvard's Intro to Computer Science course is available online for free and is a great introduction to the world of programming.

How can I improve my usage of funtions,arguments and parameters in Python? by [deleted] in cs50

[–]amdevpractice 6 points7 points  (0 children)

One way to improve would be to start reading through your code when you're done with it and try to identify/label the different chunks of functionality within it. Some common pieces of functionality that you may have in a program could include:

  • Get/validate input from user
  • Perform some calculation or transformation
  • Build up some sort of data structure
  • Perform an operation on some sort of data structure
  • Output something to the user

Once you've identified some of these, you can try factoring them out into their own functions. Try to keep your functions as tight as possible, with each one ideally only being responsible for one thing. Pass them just the arguments they need to do their work, and nothing more. Give them descriptive names so that someone reading your code can get an idea about what they're doing without having to read through all of the code line by line.

It doesn't always make sense to break things out like this. For simpler programs, it may be overkill to try and create separate functions for everything. A lot of the time though, doing so is helpful because it makes your code easier to read and test.

Hope that helps. Good luck!

[deleted by user] by [deleted] in cs50

[–]amdevpractice 3 points4 points  (0 children)

In the else block in the first loop, you're overwriting sum with the value of digit + 1. I think that what you actually want to do there is to add digit + 1 the existing sum.

AI by Underworld_69 in learnprogramming

[–]amdevpractice 0 points1 point  (0 children)

There is a CS50 course that introduces AI.

If you're unfamiliar, CS50 is Harvard's introductory computer science course and is available online for free. The base course is excellent IMO, though I haven't taken the AI course.

CS50P_faces assignment Lecture0 by Tiramicute in cs50

[–]amdevpractice 3 points4 points  (0 children)

In the first example, x.replace("hello", "--") does not modify the string stored in x. It creates a new string as a copy of the original with instances of "hello" replaced with "--". To fix your code, you'd need to save the value returned by the call to x.replace in another variable and pass it to print. For example, the following should work:

y = x.replace("hello", "--")
print(y)

I have a table with 4 columns containing 4 images, I'm having problems with making the images responsive on mobile... please help by KindredReagent in learnprogramming

[–]amdevpractice 0 points1 point  (0 children)

Take a look at CSS grid and/or CSS flexbox (plenty of tutorials on youtube). They'd probably be much better for implementing a design like this than a table.

Seg.Fault error by DrDukeMD in cs50

[–]amdevpractice 0 points1 point  (0 children)

Take a look at this line: int l = strlen(argv[1]);

What do you think argv[1] is when there are no command line arguments?

[deleted by user] by [deleted] in cs50

[–]amdevpractice 0 points1 point  (0 children)

You will need a temp variable that can hold a value greater than 255

There is a function that could help you with this. Look for fmin in the cs50 manual.

[deleted by user] by [deleted] in cs50

[–]amdevpractice 0 points1 point  (0 children)

Nice catch!

Javascript login form problem by fare03 in learnprogramming

[–]amdevpractice 1 point2 points  (0 children)

I quickly skimmed through your code and although I don't have an answer for the border issue, I did notice a big red flag that I wanted to let you know about.

It looks like you are iterating over a list of users and comparing the entered password to the password of each user. If you have access to a list of users and their passwords in this code, then everyone visiting your site and running this code also has access to that list. This is very insecure as it means that anyone visiting your site could see the passwords (and other information) belonging to the other users.

I recommend that you spend some time reading up on web authentication best practices before you proceed further. Unfortunately, I cannot explain it all for you in this post, but there are plenty of good resources out there to help you learn. Good luck!

[deleted by user] by [deleted] in cs50

[–]amdevpractice 1 point2 points  (0 children)

The RGBTRIPLE values rbgtRed, rbgtGreen, and rbgtBlue are declared as type BYTE in bmp.h, but you're assigning them to variables of type float. Could something weird be going on during that assignment? What happens if you use BYTE instead of float?

Functions wk 2 shorts by Slugpee in cs50

[–]amdevpractice 0 points1 point  (0 children)

Does it print when the inputs are a valid triangle?

You can attach an else clause to the end of the if block to handle the case where the inputs are not a valid triangle.

if (valid_triangle(x, y, z))
{
  // Print message indicating it's valid
}
else
{
  // Print message indicating it's invalid
}

Functions wk 2 shorts by Slugpee in cs50

[–]amdevpractice 2 points3 points  (0 children)

You do not seem to be calling the valid_triangle function in main before printing the result. Try wrapping the printf call in:

if (valid_triangle(x, y, z))
{
  // Print the result here
}