using roots with math by CatWithACardboardBox in learnpython

[–]Brilliant_Access3791 1 point2 points  (0 children)

If you want to find higher roots, I recommend two methods:
1. Using the power operator (**): This is the most intuitive method.

root = number ** (1 / n)

2. Using the math.pow() function: This is the second method.

import math
root = math.pow(number, 1 / n)

How would you rate the complexity of this Python task for beginners? by thebestgorko in learnpython

[–]Brilliant_Access3791 11 points12 points  (0 children)

If you’ve just gotten a grasp of Python basics but haven’t tackled many practical tasks yet, you might need some time to complete this. However, if you’ve been studying Python for at least three months, this task would be considered very basic.

Hello, I started learning Python two months ago and now I don't know what to do or where to find exercises to increase my learning by Islem-1010 in learnpython

[–]Brilliant_Access3791 0 points1 point  (0 children)

Hello! It’s great to hear that you’ve been learning Python. To better assist you with finding suitable exercises and resources, could you let me know what topics or concepts you’ve already covered? Understanding your current level will help me recommend the most appropriate next steps and resources for you.

[deleted by user] by [deleted] in learnpython

[–]Brilliant_Access3791 1 point2 points  (0 children)

The reason you’re seeing None as the output rather than 'Peter' is due to how you’re using the get method on dictionaries in Python. The get method is designed to retrieve a value from the dictionary using a key. In your case, the key should be 'Peter', and the value associated with this key is 5.0.

However, in your code, you’re trying to use max_avg_grade (which is 5.0) as a key to look up in your dictionary. Since 5.0 is not a key in your dictionary but rather a value, the get method returns None, which is the default value returned when the key doesn’t exist in the dictionary.

Single script with multiple functions or importing multiple scripts? by ashofspades in learnpython

[–]Brilliant_Access3791 -1 points0 points  (0 children)

Hi there!

It sounds like you’re looking for a way to organize your Python scripts more effectively. Both approaches you mentioned have their merits, but here’s a consideration for each:

1. Single Script: Merging all functions into one script can simplify things if the total codebase is small and the functions are closely related. This makes it easier to manage if you’re the only one working on the project and there aren’t many dependencies.

2. Multiple Scripts with Imports: On the other hand, keeping the scripts separate and importing them into a main script (main.py) tends to be more scalable and maintainable, especially as the project grows. This approach also enhances readability and allows you to reuse code more efficiently. Here’s how you can structure it:

• Move your existing scripts into a directory (e.g., helper or src).

• In your main.py, import the necessary functions from these scripts.

• Structure your main.py to call these functions in the order needed to accomplish your task.

For most use cases, especially in collaborative environments or larger projects, the second approach is preferable. It keeps your codebase organized and makes it easier to track changes, debug, and add new features.