I want to write a code that gets input from the user and the make a list of numbers from 1 to 100 and divide it into 5 sectors and check if the input is in which sector.
for example: the input is 23 and the computer will see that the number is in which sector of the list that we made and tell the user that the number is in which sector. in are example the output is: 2 here is the code:
input = input("please give a number from 1 to 100: ")
for i in range(0, 100, 20):
if i == input[0]:
print("1")
if i == input[1]:
print("2")
print(input)
note: tis is not the right code.
This will take the users input and see if it is in a certain range or give the count of the "sector" that it is in (0-20 = Sector 1, 20-40 = Sector 2)
userInput = input("please give a number from 1 to 100: ")
split = 20
count = 0
for i in range(0, 100, split):
count += 1
if i < int(userInput) <= i+split:
print("Input in range:", i, i+split)
print("Input in sector:", count)
print(userInput)
Output:
please give a number from 1 to 100: 66
Input in range: 60 80
Input in sector: 4
66
If the entered value is one of the range numbers (e.g. entered value is 20) then it will be placed in the upper range (20 to 40) not the lower range (0 to 20). You can change that by having i <= int(userInput) < i+split
instead of i < int(userInput) <= i+split