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
Sudip Bhandari
Expert
last year

When using PARTITION BY and ORDER BY in SQL window functions, the order of these clauses inside the OVER() is very important—and here's why:

LAG(age) OVER (PARTITION BY country ORDER BY age)
  • PARTITION BY comes first because it splits the data into groups (partitions) based on the specified column (in this case, country).
    Think of it like creating smaller, isolated "mini-tables" within your result set for each country.

  • ORDER BY comes after, because once the data is partitioned, you need to define the order within each partition.
    Functions like LAG and LEAD depend on the order to know which previous or next row to reference.

Now, your code doesn't run because you have placed ORDER BY first before PARTITION BY. However, SQL needs to know the groups before it can order within those groups.

Hope this helps!

SQL
This question was asked as part of the Learn SQL Basics course.
Sudip Bhandari
Expert
last year

Hi there! for (int side : sides) is a common way of using a for-each loop in Java to iterate over elements in an array or a collection.

Let's break it down:

  • sides is an array of integers. In our context, it represents the lengths of the sides of a polygon.

  • int side declares that each element from the sides array will be treated as an integer and named side during each iteration of the loop.

  • for (int side : sides) means "for each integer side in the sides array, do something..." In this case, we are summing all the side lengths to calculate the perimeter of a polygon.

This code snippet inside the loop:

perimeter = perimeter + side;

...adds the current side value to the perimeter. After iterating through all the sides in the array, the variable perimeter will hold the total sum, representing the perimeter of the polygon.

Hope this helps clarify things! Feel free to ask if you have any more questions!

Java
This question was asked as part of the Learn Java OOP course.
Mergim Berisha
PRO
last year
Mergimcountry asked
Sudip Bhandari
Expert
last year

Let me try to explain the concept.

A number is called prime if it is only divisible by 1 and itself. If no other number can divide it exactly, then the number is prime.

So to check if a number is prime, we try dividing it by all numbers between 2 and (number - 1).

  • If it divides evenly by any of them, it's not a prime number.

  • If it doesn’t divide evenly by any, then it's prime.

Here’s a function that checks if a number is prime:

void isPrime(int number) {
    int flag = 0;

    for (int i = 2; i < number; ++i) {
        if (number % i == 0) {
            flag = 1;
        }
    }

    if (flag == 0) {
        printf("%d\n", number);
    }
}

Here,

  • We run a loop from 2 to number - 1.

  • In each iteration, we check if number is divisible by i.

  • If it is divisible, we set flag to 1 (meaning it’s not prime).

  • After the loop, if flag is still 0, it means the number is prime, and we print it.

Then, in the main() function, we can call isPrime() for a range of numbers:

int main() {
    
    int x, y;
    scanf("%d %d", &x, &y);
    
    // run the loop from x to y
    // for each iteration of loop call isPrime()
    for (int i = x; i <= y; ++i) {
        isPrime(i);
    }
    
    return 0;
}

Hope this helps and makes the concept clearer! Feel free to reach out if you have more questions or need further assistance.

C
This question was asked as part of the Practice: C Programming course.
Sudip Bhandari
Expert
last year

To initialize a string in Python, you simply need to wrap your text in either single quotes (' ') or double quotes (" "). Both methods are valid and work identically, so you can use whichever you prefer or find more readable at the moment.

Here's an example:

# Using double quotes
my_string1 = "Hello, World!"

# Using single quotes
my_string2 = 'Python is fun!'

And just for a little reminder, no matter the quotes you choose, everything inside them is considered a string, and Python treats them the same way.

Hope this helps! Let me know if you have more questions.

This question was asked as part of the course.
Sudip Bhandari
Expert
last year

Leaving an empty line in code is simply a common practice to make the code more readable.
It doesn’t affect how the code is executed at all.

When the code gets longer, we often leave empty lines to separate different parts or group related actions together—this makes it easier to read and understand.

For example:

color1 = "blue"
print(color1) 

color2 = "pink"

color1 = color2

print(color1) 
print(color2)

In this code:

  • The first two lines are about creating and printing color1.

  • The next group changes the value of color1 and prints both color1 and color2.

Hope this clears things up! Let me know if you have more questions.

Python
This question was asked as part of the Getting started with Python course.
Sudip Bhandari
Expert
last year

Hi there! It's perfectly normal to feel confused at the beginning, so let's clarify the differences between a variable, a comment, and a string in Python.

1. Variable: A variable is like a labeled box that holds data in your program. You give it a name to reference the data later on. For example, if you wanted to store someone's age, you might use:

age = 25

In this line, age is the variable name, and it's storing the number 25.

2. Comment: Comments are messages in the code meant for humans to read, not for the computer. They help explain what a part of the code does. Python ignores comments when running the code. You create a comment using the # symbol:

# This is a comment
print("Hello, World!")   # This prints a greeting message

Comments won't affect your code's output; they're just there to help you and others who read your code.

3. String: A string is a sequence of characters (like letters, numbers, and symbols) enclosed in quotes. Strings are like text data. You use either single (' ') or double (" ") quotes to define a string. For example, "Hello, World!" is a string:

greeting = "Hello, World!"

In this example, greeting is a variable storing the string "Hello, World!".

I hope this clears things up for you! Let me know if there's anything else that needs clarification.

Python
This question was asked as part of the Getting started with Python course.
Apekchhya Shrestha
Expert
last year

You can think of comments as helpful notes you leave in your code. They're not run by the compiler, they're just there to make the code easier to understand.

Right now, your code might be simple enough to follow without them, but as programs get more complex, comments become extremely useful, especially when someone else is reviewing your code.

Using comments early on is a great habit! They help you (and others) quickly understand what different parts of the code do, even after a long break.

Hope this helps! Feel free to ask more questions if you're curious.

C++
This question was asked as part of the Learn C++ Basics course.
M
last year
Madoccountry asked
Apekchhya Shrestha
Expert
last year

A quotient is the result you get when you divide one number by another. For example:

  • 10 ÷ 2 = 5 → Quotient is 5
  • 15 ÷ 3 = 5 → Quotient is 5
  • 20÷ 4 = 5 → Quotient is 5
  • 9 ÷ 2 = 4 (with remainder 1) → Quotient is 4

The quotient is just the whole number part of the division result (ignoring the remainder, unless you're working with decimals).

Hope that clears it up! Let me know if you'd like more clarification on this.

Python
This question was asked as part of the Getting started with Python course.
Jay Harris
last year
Jaycountry asked
Apekchhya Shrestha
Expert
last year

Great question!

In Python, int stands for integer, which means a whole number — no decimal points.

For example:

  • 5, 100, and -3 are all integers.

You can also use the int() function in Python to convert other types into integers:

  • int(3.7) will become 3

  • int("15") will become 15

This is really useful when you're working with numbers and want to make sure you're using whole numbers for calculations.

Hope this helps! Let me know if you have more questions.

Python
This question was asked as part of the Getting started with Python course.