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
Udayan Shakya
Expert
last year
Udayan Shakya answered

Hello, Daniel. You can't use commas for float numbers in Python (you must use dot). This is because Python recognizes the dot as the standard way to indicate the fractional part of a number.

For example:

print(3.14)  # This is a float
print(2.5)   # This is also a float

Using a comma instead of a dot can lead to errors or unexpected behaviors. For instance:

# This will print 3 and 14 as separate numbers
print(3,14)

In this case, Python treats 3 and 14 as two separate arguments, so it would output them as 3 14 (two numbers), instead of recognizing them as a single float number.

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.
N
Expert
last year
Nisha Sharma answered

Hello there, nice question!

The double slash // is used in Python for integer division. Unlike the single slash /, which returns a decimal value, // divides the numbers and gives the result as a whole number. Since the formula for the sum of natural numbers always results in an integer, using // helps keep the output clean and avoids unnecessary decimal points.

Feel free to reach out if you have any more queries.

Python
This question was asked as part of the DSA with Python course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Good question! The reason we use quotation marks for words (strings) and not for numbers is that quotation marks tell Python that the value inside them should be treated as text, or a string.

For example, when you write `"Python"`, Python knows to treat it as a series of characters, which is a string. On the other hand, writing just `75` without quotes tells Python it's a number, or an integer, which can be used in calculations. So when you're printing or using these values, the quotes help Python distinguish between text and numbers.

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.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

To add items to a dictionary, you can use dictionary assignment. Here’s a simple explanation:

Steps to Add Key-Value Pairs to a Dictionary

  1. Create an Empty Dictionary: Start with an empty dictionary using {}.

    my_dict = {}
  2. Define Your Loop: Use a for loop to iterate a set number of times, asking the user for key-value pairs.

    for i in range(3): # This loop will run three times
  3. Get User Input for Key and Value: During each iteration, prompt the user for a key and a value.

    key = input("Enter the key: ") value = input("Enter the value: ")
  4. Add the Key-Value Pair to the Dictionary: Use assignment to add them to the dictionary.

    my_dict[key] = value
  5. Print the Dictionary: Once you’ve added all key-value pairs, print the dictionary to see the result.

    print(my_dict)

Here’s how your code might look after incorporating these elements:

# create an empty dictionary named my_dict
my_dict = {}

# use for loop to iterate and gather user input
for i in range(3):
    key = input("Enter the key: ")
    value = input("Enter the value: ")
    my_dict[key] = value  # add the key-value pair to the dictionary

# print the final dictionary
eprint(my_dict)

I hope this clears things up! Feel free to ask any follow-up questions if you need more clarification. 😊

Python
This question was asked as part of the Practice: Python Basics course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hello Hannes! Yes, 4**3 in Python is the same as 4^3 in Excel. This operation is known as exponentiation, which is raising a number to the power of another.

Basically,

4**3 = 4 * 4 * 4 = 64 

Hope this clarifies things for you! Let me know if you have any more questions. Happy coding!

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

Python doesn’t care about singular/plural. languages is the list name, and language is just a variable you chose to store each item one by one, and you can name it anything like item or x. People often use language because it makes the code easier to read.

Example:

languages = ["English", "German", "French"]
for item in languages:
    print(item)

If you have more questions, I am here to help.

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

Hi Alan, that’s a great question.

In Python, powers work a little differently from what you see on most calculators. Calculators usually use the ^ symbol for exponents, so it’s normal to try the same thing in Python. The tricky part is that Python doesn’t use ^ for powers at all, so it won’t give the result you expect.

The Python way to calculate a power is with two stars. So if you want “4 to the power of 3,” you write:

4 ** 3

Python reads that as “multiply 4 by itself three times,” which gives:

4 * 4 * 4 = 64

You can do the same with decimals:

2.5 ** 3   # 15.625

Once you get used to **, it becomes pretty straightforward.

If you have more questions while you’re learning, I’m happy to help.

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

Great question. This trips a lot of people up when they first start using Python.

The key thing to remember is that range() stops one number before the value you put in as the second argument. So if you write:

range(1, n)

Python will count like this:

1, 2, 3, ..., n-1

It never reaches n, which is why your loop feels like it’s stopping too early.

If you actually want to include n in the loop, just add 1 to the stop value:

for i in range(1, n + 1):
    total_sum += i

Now Python will count:

1, 2, 3, ..., n

and you get the full sum you expected.

If anything still feels confusing, I’m happy to walk through another example with you.

Python
This question was asked as part of the Practice: Python Basics course.
Abhay Jajodia
Expert
last year
Abhay Jajodia answered

Hello Danielle, really nice question.

Any time you use a comparison in Python — things like ==, >, <, >=, and so on — Python evaluates that expression and decides whether it’s true or false. The result of that decision is always a Boolean value: True or False.

For example:

total = 150
result = total > 100
print(result)   # True

Here Python checks the comparison, finds that 150 really is greater than 100, and gives you True. If the comparison wasn’t correct, you’d get False instead.

That’s just how comparisons work in Python:
they always produce a Boolean value.

If you have further questions, I'm here to help.

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

Hello Arushi, really nice question.

Both *args and **kwargs let a function take a flexible number of arguments, but they work in different ways.

*args collects positional arguments. These are the values you pass without naming them:

def demo(*args):
    print(args)

demo(1, 2, 3)
# (1, 2, 3)

So args turns into a tuple of whatever positional values you give.

**kwargs collects keyword arguments — the ones you pass using names:

def demo(**kwargs):
    print(kwargs)

demo(name="Arushi", age=20)
# {'name': 'Arushi', 'age': 20}

This becomes a dictionary where the keys are the argument names.

The simple way to remember it:

  • *args → any number of unnamed values

  • **kwargs → any number of named values

They’re both handy when you don’t know ahead of time how many arguments someone will pass into your function.

If you have further questions, I'm here to help.

Python
This question was asked as part of the Learn Python Intermediate course.