Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Python practice program which finds the sum of digits in a number.

Notifications You must be signed in to change notification settings

seanfisk/python-sum-of-digits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Sum of the Digits Python Assignment

The following is another Python practice assignment.

Specifications

The function sum_of_digits should be able to take a number in string form, and return the sum of the digits of that number. Note that the function takes a string as its only parameter (Python type str), not an integer (Python type int). To complete the assignment, you will have to convert characters to integers. The way you do this is up to you. The Python documentation on Numeric Types and the integer function may help you out.

Examples

>>> sum_of_digits('1234')
10
>>> sum_of_digits('434')
11
>>> sum_of_digits('1111')
4
>>> sum_of_digits('')
0
>>> sum_of_digits('abcd')
SomeError (I will help you with this)

Purpose

  • Review basic git skills.
  • Review of Test-Driven Development in Python using unittest.
  • Practice writing tests for TDD.
  • Practice basic Python data manipulation skills.

Instructions

  • Log in to your GitHub account.
  • Fork my repository by following GitHub's guide to Forking a Repo.
  • Clone the code from your new repository using the GitHub client.
  • Run the test suite by running python test_sum_digits.py on the command-line. Zero tests should be run.
  • Add tests to test_sum_digits.py to match the specifications.
    • Don't write any code yet! Make sure to write the tests first.
    • Don't forget to add tests for the empty string. Don't worry about error checking; I will help you with this later. Remember that your code is only as good as your tests!
  • Complete the code in sum_digits.py such that it passes all the tests.
  • Add extra tests if necessary and refactor the code.
  • Commit the code locally using the GitHub client.
  • Sync the code to your repository.
  • Submit a pull request to my original repository.

Extras

I will help you with error checking at our next meeting.

About

Python practice program which finds the sum of digits in a number.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages