SimeonTs

SUPyF2 D.Types and Vars Lab - 03. Special Numbers

Sep 26th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. """
  2. Data Types and Variables - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1721#2
  4. Video: https://www.youtube.com/watch?v=i2vHypjJkB4
  5.  
  6. SUPyF2 D.Types and Vars Lab - 03. Special Numbers
  7.  
  8. Problem:
  9. A number is special when its sum of digits is 5, 7 or 11.
  10. Write a program to read an integer n and for all numbers in the range 1…n to print the number and if it is special or not (True / False).
  11. Input:
  12. 15
  13. Output:
  14. 1 -> False
  15. 2 -> False
  16. 3 -> False
  17. 4 -> False
  18. 5 -> True
  19. 6 -> False
  20. 7 -> True
  21. 8 -> False
  22. 9 -> False
  23. 10 -> False
  24. 11 -> False
  25. 12 -> False
  26. 13 -> False
  27. 14 -> True
  28. 15 -> False
  29. """
  30.  
  31. n = int(input())
  32. for num in range(1, n + 1):
  33.     sum_of_digits = 0
  34.     digits = num
  35.     while digits > 0:
  36.         sum_of_digits += digits % 10
  37.         digits = int(digits / 10)
  38.     if (sum_of_digits == 5) or (sum_of_digits == 7) or (sum_of_digits == 11):
  39.         print(f"{num} -> True")
  40.     else:
  41.         print(f"{num} -> False")
Add Comment
Please, Sign In to add comment