Skip to content

London | 26-Jul-SDC | Boshra Mahmoudi| Sprint 5 | Prep Exercises - #679

Open
BoshraM wants to merge 23 commits into
CodeYourFuture:mainfrom
BoshraM:15-prep-exercises
Open

London | 26-Jul-SDC | Boshra Mahmoudi| Sprint 5 | Prep Exercises#679
BoshraM wants to merge 23 commits into
CodeYourFuture:mainfrom
BoshraM:15-prep-exercises

Conversation

@BoshraM

@BoshraM BoshraM commented Aug 31, 2026

Copy link
Copy Markdown
  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1155

@BoshraM BoshraM added 📅 Sprint 5 Assigned during Week 5 of this module Module-Tools The name of the module. labels Aug 31, 2026
@BoshraM BoshraM added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Sep 2, 2026

@Khantdotcom Khantdotcom left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Mandatory fix:

  • ValueError in sprint5/type-guided-refactorings.py

Not mandatory but code better

  • Use python's built-in methods

Comment thread sprint5/Exercise1.py Outdated
def format_pence_as_string(total_pence: int) -> str:
if total_pence < 100:
return f"{total_pence}p"
pounds = int(total_pence / 100)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For calculating round numbers after division, check out this article (python's built-in floor division) here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@Khantdotcom Thanks for the article. I replaced my code with // to use floor division.

laptops = [
Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system="Arch Linux"),
Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="Ubuntu"),
Laptop(id=3, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system="ubuntu"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A type here. Could raise ValueError.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks @Khantdotcom, for reviewing my code. Can you explain how it can cause a ValueError, please? I assume you are pointing to "ubuntu", which is lowercase here. In this case, I don't see any error being thrown, except that it will miss the laptop with ID 3 as a possibility. I think that's also why we use enums in the next exercise to fix this issue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ah, you are completely right, @BoshraM! That was a slip on my part.

I meant to type "typo" rather than "type," and you are entirely correct that it won't raise a ValueError. Standard Python will just evaluate the string comparison to False, leading to a silent logic bug where Laptop ID 3 is missed, just as you described.

Comment thread sprint5/Exercise1.py Outdated
balances[name] = amount

def sum_balances(accounts: dict[str, int]) -> int:
total = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you find out another "short" way to calculate the sum of dict.values , using built-in method, which could save you time?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks @Khantdotcom , I've changed it to sum(accounts.values()).

@Khantdotcom Khantdotcom left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Clean code and sound logic. Great job and keep up the good work!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Tools The name of the module. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 5 Assigned during Week 5 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants