angryatti

IntervalDivisorsWithCustomValue_Pythonv3

Feb 1st, 2026 (edited)
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Jan 29 20:55:24 2026
  4.  
  5.  
  6. pip install cooked-input
  7.  
  8.  
  9. @author: angry
  10. """
  11. from cooked_input import get_int
  12.  
  13.  
  14. def intervalDivisors(beginning,ending,divisor):
  15.     countofDiv = 0
  16.  
  17.     for i in range (beginning,ending+1,1):
  18.         if i % divisor == 0:
  19.             countofDiv+=1
  20.     return countofDiv
  21.        
  22.  
  23. class messageAndValue:
  24.     message: str
  25.     valueA: int
  26.     valueB: int
  27. def inputAB()->messageAndValue():
  28.  
  29.     print(f'Is it dividable? {divisorValue}\n')
  30.    
  31.    
  32.     a = get_int(prompt="Give the beginning value of the interval:\n")
  33.     b = get_int(prompt="Give the final value of the interval:\n")
  34.  
  35.    
  36.     mess = messageAndValue()
  37.  
  38.     mess.message = "Default"
  39.     mess.valueA = a
  40.     mess.valueB = b
  41.    
  42.     if (mess.valueA<0):
  43.         mess.message ="The beginning of the interval cannot less then zero"
  44.         mess.valueA = -1
  45.         mess.valueB = -1
  46.         return mess
  47.     elif (mess.valueB<0):
  48.         mess.message = "The final of the interval cannot less then zero"
  49.         mess.valueA = -1
  50.         mess.valueB = -1
  51.         return mess
  52.        
  53.     elif (mess.valueA>mess.valueB):
  54.         mess.message ="The first value bigger than second"
  55.         return mess
  56.     elif (mess.valueA==mess.valueB):
  57.         mess.message ="Not a good value because it is equal"
  58.         return mess
  59.     else:
  60.         mess.message = f'The given interval has {divisorValue} divisors: '
  61.         return mess
  62.  
  63.  
  64. divisorValue = get_int(prompt="Give me the divisor:\n")
  65.  
  66. mess_final = inputAB()
  67.  
  68.  
  69. if (mess_final.valueA == -1 or mess_final.valueB == -1 ):
  70.     print(mess_final.message)
  71. else:
  72.     print (mess_final.message,intervalDivisors(mess_final.valueA, mess_final.valueB,divisorValue))
Advertisement
Add Comment
Please, Sign In to add comment