├── get_length.py ├── get_sum_digits.py ├── .github └── workflows │ └── homework.yml └── README.md /get_length.py: -------------------------------------------------------------------------------- 1 | #find count of digits in an integer without using for, len, while 2 | def get_length(num): 3 | x = 0 4 | x -= pow(0, num) 5 | num//=10 6 | x -= pow(0, num) 7 | num//=10 8 | x -= pow(0, num) 9 | num//=10 10 | x -= pow(0, num) 11 | num//=10 12 | x -= pow(0, num) 13 | 14 | return x+5 15 | 16 | print(get_length(100)) -------------------------------------------------------------------------------- /get_sum_digits.py: -------------------------------------------------------------------------------- 1 | #Find the sum of digits in an integer 2 | def get_sum_digits(num): 3 | count=0 4 | x1=num%10 5 | num//=10 6 | x2=num%10 7 | num//=10 8 | x3=num%10 9 | num//=10 10 | x4=num%10 11 | num//=10 12 | x5=num%10 13 | num//=10 14 | 15 | count = x1+x2+x3+x4+x5 16 | return count 17 | 18 | print(get_sum_digits(555)) -------------------------------------------------------------------------------- /.github/workflows/homework.yml: -------------------------------------------------------------------------------- 1 | name: Type conversion 2 | on: [push] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout 8 | uses: actions/checkout@v2 9 | 10 | # Checkout the repository 11 | - name: Checkout the repository 12 | uses: actions/checkout@v2 13 | with: 14 | repository: codeschooluz/digits_and_number_beginner_test 15 | token: ${{secrets.TEST_KEY}} 16 | path: test 17 | - name: Install dependencies 18 | uses: actions/setup-python@v2 19 | with: 20 | python-version: "3.9" 21 | - name: Install pytest 22 | run: | 23 | pip install pytest 24 | - name: Run tests 25 | run: | 26 | pytest -v --tb=no -q -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome 2 | # DIGITS AND NUMBER (PRACTICE) 3 | ## level 4 | - Basic 5 | - Beginner 6 | - Intermediate 7 | - Mixed 8 | - Advanced 9 | 10 | 11 | Automated grading of homework assignments and tests 12 | - fork this repository 13 | - solve the task 14 | - commit with proper message 15 | - just push and check answer 16 | # Problems 17 | ## Get length #1 18 | 19 | A integer is given. Find the number of digits in it. 20 | 21 | **Example 1:** 22 | 23 | ```Python 24 | Input: num=5 25 | Output: 1 26 | 27 | ``` 28 | 29 | **Example 2:** 30 | 31 | ```Python 32 | Input: num=87 33 | Output: 2 34 | 35 | ``` 36 | **Constraints:** 37 | - 0<=num<=105 38 | 39 | ## Sum of digits #2 40 | 41 | A integer is given. Find the sum of digits in it. 42 | 43 | **Example 1:** 44 | 45 | ```Python 46 | Input: num=5 47 | Output: 5 48 | 49 | ``` 50 | 51 | **Example 2:** 52 | 53 | ```Python 54 | Input: num=23 55 | Output: 5 56 | 57 | ``` 58 | 59 | **Example 3:** 60 | 61 | ```Python 62 | Input: num=200 63 | Output: 2 64 | 65 | ``` 66 | 67 | **Constraints:** 68 | - 0<=num<=105 69 | 70 | # Warning 71 | - don't copy other solutions or any solution 72 | - don't remove comments 73 | --------------------------------------------------------------------------------