Skip to content

Comments

[feature] Add extended math and string fns#2

Open
pushpitkamboj wants to merge 1 commit intomasterfrom
feature/extended_python_fns
Open

[feature] Add extended math and string fns#2
pushpitkamboj wants to merge 1 commit intomasterfrom
feature/extended_python_fns

Conversation

@pushpitkamboj
Copy link
Collaborator

added the math and string manipulation functions. Fixes #1

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds beginner-friendly math and string utility functions to pushpit/main.py and updates the demo main() output to showcase them (per Issue #1).

Changes:

  • Added average, factorial, min/max, reverse string, and palindrome helper functions.
  • Expanded main() to print a structured demo of the new math and string operations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +102
for word in test_words:
result = "is" if is_palindrome(word) else "is not"
print(f" '{word}' {result} a palindrome")
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In main(), the loop for word in test_words: reuses the word variable name that was just used for the earlier string example. Using a different loop variable name (e.g., test_word) would avoid shadowing and be clearer for beginners.

Suggested change
for word in test_words:
result = "is" if is_palindrome(word) else "is not"
print(f" '{word}' {result} a palindrome")
for test_word in test_words:
result = "is" if is_palindrome(test_word) else "is not"
print(f" '{test_word}' {result} a palindrome")

Copilot uses AI. Check for mistakes.
Comment on lines +17 to +19
"""Calculate the average of a list of numbers."""
if not numbers:
return 0.0
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculate_average returns 0.0 for an empty list, which is not a meaningful average and is inconsistent with find_max/find_min returning None on empty input. Consider making the empty-input behavior explicit (e.g., raise ValueError, or return None and change the return type to Optional[float]).

Suggested change
"""Calculate the average of a list of numbers."""
if not numbers:
return 0.0
"""Calculate the average of a list of numbers.
Raises:
ValueError: If the list of numbers is empty.
"""
if not numbers:
raise ValueError("Cannot calculate average of an empty list")

Copilot uses AI. Check for mistakes.
Comment on lines +29 to +34
"""Calculate factorial of a number recursively."""
if n < 0:
raise ValueError("Factorial is not defined for negative numbers")
if n <= 1:
return 1
return n * factorial(n - 1)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

factorial is implemented recursively, which will raise RecursionError for larger n due to Python's recursion limit. An iterative implementation avoids that failure mode while keeping the function beginner-friendly.

Suggested change
"""Calculate factorial of a number recursively."""
if n < 0:
raise ValueError("Factorial is not defined for negative numbers")
if n <= 1:
return 1
return n * factorial(n - 1)
"""Calculate factorial of a number iteratively."""
if n < 0:
raise ValueError("Factorial is not defined for negative numbers")
if n <= 1:
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result

Copilot uses AI. Check for mistakes.
print("=" * 40)
print("Python Demo Program")
print("=" * 40)

Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is trailing whitespace on this blank line, which can cause noisy diffs and linting failures. Remove the spaces so the line is empty.

Suggested change

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add math and string functions

3 participants