Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggested Python Coding Challenges: Easy and Medium Levels #36

Open
malakbattat opened this issue Jan 5, 2025 · 4 comments
Open

Suggested Python Coding Challenges: Easy and Medium Levels #36

malakbattat opened this issue Jan 5, 2025 · 4 comments
Labels
challenge a new challenge Discussion For conversations or brainstorming sessions about team processes or project direction

Comments

@malakbattat
Copy link

malakbattat commented Jan 5, 2025

Python Coding Challenges: Easy, and Medium Problems

Easy Challenges

1. Palindrome Check

Problem: Write a function that checks if a given string is a palindrome (reads the same forward and backward).

  • Explanation: A palindrome is a word, phrase, or sequence that reads the same backward as forward. This is a simple string manipulation task.
  • Function signature: def is_palindrome(s: str) -> bool:
  • Test cases:
    • is_palindrome("racecar") should return True
    • is_palindrome("hello") should return False
  • References:

2. Sum of Digits

Problem: Write a function that calculates the sum of digits of a given integer.

  • Explanation: This function should take an integer as input and return the sum of its digits. A simple loop can be used to extract each digit.
  • Function signature: def sum_of_digits(n: int) -> int:
  • Test cases:
    • sum_of_digits(1234) should return 10
    • sum_of_digits(987) should return 24
  • References:

3. Temperature Converter

Problem: Write a function to convert temperature from Celsius to Fahrenheit and vice versa.

  • Explanation: The function should take a temperature and the unit (Celsius or Fahrenheit) and convert it to the other unit.
  • Function signature: def convert_temperature(value: float, unit: str) -> float:
  • Test cases:
    • convert_temperature(100, 'C') should return 212.0 (Celsius to Fahrenheit)
    • convert_temperature(32, 'F') should return 0.0 (Fahrenheit to Celsius)
  • References:

Medium Challenges

4. Prime Number Check

Problem: Write a function that checks if a number is prime.

  • Explanation: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. This requires checking divisibility up to the square root of the number.
  • Function signature: def is_prime(n: int) -> bool:
  • Test cases:
    • is_prime(7) should return True
    • is_prime(10) should return False
  • References:

5. Leap Year Checker

Problem: Write a function to check if a year is a leap year.

  • Explanation: A year is a leap year if it is divisible by 4, but not divisible by 100 unless it is also divisible by 400.
  • Function signature: def is_leap_year(year: int) -> bool:
  • Test cases:
    • is_leap_year(2020) should return True
    • is_leap_year(2023) should return False
  • References:

6. String Compression

Problem: Write a function that compresses a string using the counts of repeated characters. For example, "aaabbbcc" becomes "a3b3c2". If the compressed string is not shorter than the original string, return the original string.

  • Explanation: This challenge requires handling string manipulation and efficiently counting character repetitions.
  • Function signature: def compress_string(s: str) -> str:
  • Test cases:
    • compress_string("aaabbbcc") should return "a3b3c2"
    • compress_string("abc") should return "abc"
  • References:
@malakbattat malakbattat added challenge a new challenge Discussion For conversations or brainstorming sessions about team processes or project direction labels Jan 5, 2025
@malakbattat malakbattat changed the title Python Coding Challenges Suggestions: Easy, and Medium Suggested Python Coding Challenges: Easy and Medium Levels Jan 5, 2025
@malakbattat malakbattat added challenge a new challenge and removed challenge a new challenge labels Jan 5, 2025
@github-project-automation github-project-automation bot moved this from TODO to READY FOR REVIEW in ET6 Foundations Group 17 Jan 6, 2025
@malakbattat malakbattat moved this from READY FOR REVIEW to TODO in ET6 Foundations Group 17 Jan 6, 2025
@malakbattat malakbattat reopened this Jan 6, 2025
@abdoalsir
Copy link

Thank you Malak for sharing such useful suggestions

@MaRia19280
Copy link

Wow this is amazing, malak!!!

@MaherAssaf19
Copy link

Thanks Malak, for sharing your suggestions, they are well explained. great work!

@MuhannadGTR
Copy link

Thank you Malak, for your suggestions and your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
challenge a new challenge Discussion For conversations or brainstorming sessions about team processes or project direction
Projects
Development

No branches or pull requests

5 participants