Ask Programiz - Human Support for Coding Beginners

Explore questions from fellow beginners answered by our human experts. Have some doubts about coding fundamentals? Enroll in our course and get personalized help right within your lessons.

  • All
  • Python
  • C
  • Java
  • CPP
  • SQL
  • JS
  • HTML
  • CSS
Kelish Rai
Expert
last year
Kelish Rai answered

Coding is a lot like mathematics—the best way to memorize it is through consistent practice.

Try writing small pieces of code regularly and experiment with different examples. The more you practice, the more familiar the concepts will become, and the easier it'll be to remember them.

Also, try breaking things down into smaller chunks. Instead of trying to learn everything at once, focus on one concept at a time and practice it until it feels comfortable.

Don't worry if you forget something; it’s completely normal. With time, things will start to click.

Java
This question was asked as part of the Learn Java Basics course.
Kelish Rai
Expert
last year
Kelish Rai answered

If you're familiar with PEMDAS, the expression 2 * 5 - 10 / 5 follows the same order of operations.

Here’s a quick breakdown of PEMDAS:

  1. Parentheses first (none here).

  2. Exponents next (none here).

  3. Multiplication and Division, from left to right.

  4. Addition and Subtraction, from left to right.

Now, let’s see how Python evaluates the expression step by step:

  1. 2 * 5 = 10, so the expression becomes 10 - 10 / 5.

  2. 10 / 5 = 2.0, so now we have 10 - 2.0.

  3. 10 - 2.0 = 8.0.

Since division in Python always produces a float, the final result is 8.0 instead of an integer.

However, if you want the result without decimals, you can use // for integer division.

result = 2 * 5 - 10 // 5
print(result)  # Output: 8

In this case, the result would be an integer (8), not a float (8.0).

Python
This question was asked as part of the Getting started with Python course.
Kelish Rai
Expert
last year
Kelish Rai answered

It seems there’s a slight confusion about what you're trying to achieve.

Firstly, "greeting" = "Merry Christmas" is incorrect, as you don’t need to enclose variables within quotation marks. The correct syntax would be:

greeting = "Merry Christmas"

This way, greeting is correctly defined as a variable. Whereas Python would treat "greeting" as a string instead.

Similarly, the line print("greeting") won’t print "Merry Christmas" because of the quotation marks.

To correctly print the value of the greeting variable, you should write:

print(greeting)

This will output "Merry Christmas" as expected.

Note: Think of variables as "labels" for values. If you wrap the label in quotes, Python thinks it's just a word, not a label pointing to something else.

Python
This question was asked as part of the Getting started with Python course.
Kelish Rai
Expert
last year
Kelish Rai answered

Yes, a double in Java can store both whole numbers (integers) and decimal numbers (floating-point values).

For example:

// Store an integer
double num1 = 10;

// Store a decimal number
double num2 = 10.5;

Note that even though 10 is an integer, Java automatically converts it to 10.0 when stored in a double variable.

Java
This question was asked as part of the Learn Java Basics course.
Kelish Rai
Expert
last year
Kelish Rai answered

Here's how you can check with an if...else statement whether a value is a character or not:

if ((alphabet >= 'a' && alphabet <= 'z') || (alphabet >= 'A' && alphabet <= 'Z')) {
    printf("Alphabet");
} else {
    printf("Not an Alphabet");
}

Here,

  • The condition alphabet >= 'a' && alphabet <= 'z' checks if the character is a lowercase letter (from a to z).

  • The condition alphabet >= 'A' && alphabet <= 'Z' checks if it’s an uppercase letter (from A to Z).

  • The || (OR) operator ensures that if either condition is true, the program will print "Alphabet".

  • If neither condition is true, the program prints "Not an Alphabet" in the else block.

To check if it’s a number:

If you want to check if the value is a number (digit 0-9), you can extend the logic like this:

if ((alphabet >= 'a' && alphabet <= 'z') || (alphabet >= 'A' && alphabet <= 'Z')) {
    printf("Alphabet");
} else if (alphabet >= '0' && alphabet <= '9') {
    printf("Number");
} else {
    printf("Special Character");
}

This version will now differentiate between alphabets, numbers, and special characters.

C
This question was asked as part of the Practice: C Programming course.
Daniel Ragatz
PRO
last year
Danielcountry asked
Kelish Rai
Expert
last year
Kelish Rai answered

A HashMap is not ordered in Java. It doesn’t guarantee any specific order of elements when you add or retrieve them. The reason for this is that HashMap is optimized for fast lookups, and ordering elements doesn’t contribute to its primary goal.

If you need an ordered version, you have two options:

1. LinkedHashMap: This data structure maintains the order of insertion. That means the order in which you add elements to the map will be preserved when you iterate over it.

Example:

Map linkedMap = new LinkedHashMap<>();
linkedMap.put("one", 1);
linkedMap.put("two", 2);
linkedMap.put("three", 3);

// Output will be in insertion order
for (Map.Entry entry : linkedMap.entrySet()) {
    System.out.println(entry.getKey() + ": " + entry.getValue());
}

2. TreeMap: This data structure automatically sorts the keys in natural order (or by a custom comparator if provided). The elements will be sorted based on the key.

Example:

Map treeMap = new TreeMap<>();
treeMap.put("banana", 2);
treeMap.put("apple", 1);
treeMap.put("cherry", 3);

// Output will be in sorted order by key
for (Map.Entry entry : treeMap.entrySet()) {
    System.out.println(entry.getKey() + ": " + entry.getValue());
}

So, if you want ordered behavior, you’d use either LinkedHashMap for insertion order or TreeMap for sorted order.

Java
This question was asked as part of the Learn Java Intermediate course.
pratik tidke
last year
Pratikcountry asked
Kelish Rai
Expert
last year
Kelish Rai answered

In HTML, metadata refers to information about the webpage that isn't visible to users directly, but it provides important details to the browser and search engines.

Some common types of metadata include things like the page's title, description, keywords, author, and character encoding.

Metadata is usually placed inside the section of the HTML document, like this:


    
    
    
    
    My Webpage

Since you're just getting started, you don't need to focus on metadata much. As you continue your web development journey, you'll gradually learn more about it and how it can help with SEO and other aspects of web development.

Hope this clears things up. Let me know if you have any confusion.

HTML
This question was asked as part of the Learn HTML course.
Kelish Rai
Expert
last year
Kelish Rai answered

When there are operators of the same precedence in an arithmetic operation, Python follows a specific rule called associativity to determine the order of evaluation.

Associativity defines the direction in which operations of the same precedence are processed:

  • Most arithmetic operators in Python (like +, -, *, /) are left-associative, meaning they are evaluated from left to right.

  • Some operators, like exponentiation (**), are right-associative, meaning they are evaluated from right to left.

Example 1: Left-to-right associativity (for - and /)

result = 20 - 5 - 2  # evaluated as (20 - 5) - 2 = 13
print(result)  # Output: 13

Example 2: Right-to-left associativity (for **)

result = 2 ** 3 ** 2  # evaluated as 2 ** (3 ** 2) = 2 ** 9 = 512
print(result)  # Output: 512

If you're ever unsure, you can use parentheses to make the order of operations explicit. For example:

# Force a different order
result = (20 - (5 - 2))  # result is 17

If you want to learn more about this, I recommend checking out the blog Understanding Operator Precedence and Associativity in Python. It explains this concept in a clear and structured way.

Python
This question was asked as part of the Getting started with Python course.
Kelish Rai
Expert
last year
Kelish Rai answered

When working on a real project, you might organize your files in a structured way using folders inside other folders. This is what we mean by a nested directory structure.

For example:

website   
│── home  
│   │── index.html
│   │── images  
│   │   │── banner.png 

Here, banner.png is inside the images folder, which is inside the home folder, making it a nested directory structure.

Since index.html is in the home folder, you’d reference the image like this:

This tells the browser to look inside the images folder, which is in the same directory as index.html, to find banner.png.

HTML
This question was asked as part of the Learn HTML course.
Kelish Rai
Expert
last year
Kelish Rai answered

When working on a real project, you might organize your files like this:

website
│── home
│   │── index.html
│   │── banner.png

Here, website is the root folder, and it contains another folder called home. Inside home, both index.html and banner.png are stored in the same location.

When we say "the image is in the same directory as the HTML file", we mean that both files exist within the same folder.

Now, inside index.html, you can easily reference banner.png like this:

This tells the browser to look for banner.png in the same folder as index.html.

HTML
This question was asked as part of the Learn HTML course.