I am trying to get my divisibility checker code to work correctly. It currently only works with whole positive numbers. If the number is a decimal or a negative number the code will not work. I know I need to add some floats, but I do not know where to add them.

```
def divisibility():
print "+------------------------------------+"
print "|Welcome to the Divisibility Checker!|"
print "+------------------------------------+"
x = raw_input("Please input a number: ")
num1 = raw_input("Number to start checking at: ")
num2 = raw_input("Number to end checking at: ")
print "Divisibility:"
for i in range(int(num1), int(num2)):
if (int(i)) % (int(x)) == 0:
print str(i) + ": Yes"
else:
pass
divisibility()
```

What I want this to do it basically print what numbers are divisible by that number imputed. So if you input 2.5, and then you want it to check from 1-10 it should return 2.5, 5, 7.5, and 10. Same as if you input -2, and it checks from 0-(-10) it should return -2, -4, -6, -8, and -10.

Based on the OP's examples, it seems that he wants to get all the integer multiples of a number between two ranges. In light of that goal, I have renamed the function `getMultiples`

.

```
from math import ceil
from math import floor
def getMultiples(x, num1, num2):
num1, num2 = min(num1, num2), max(num1, num2)
lower = ceil(float(num1) / x)
upper = floor(float(num2) / x)
lower, upper = min(lower, upper), max(lower, upper)
for i in range(int(lower), int(upper) + 1):
print i * x
getMultiples(2.5, 1, 10)
getMultiples(-2, 0, -10)
```

Output:

```
2.5
5.0
7.5
10.0
0
-2
-4
-6
-8
-10
```

There are better ways to achieve what you are trying to do as Merlins answer shows but I imagine as a beginner you are more interested in learning than proficiency.

This code is not complete but should give you enough to start with to get close to what you want.

```
def float_range(start, stop, step): # will step in any range of step passed 1, .5, .1 etc...
while start < stop:
yield start
start += step
def divisibility():
print "+------------------------------------+"
print "|Welcome to the Divisibility Checker!|"
print "+------------------------------------+"
x = raw_input("Please input a number: ")
num1 = (raw_input("Number to start checking at: "))
num2 = (raw_input("Number to end checking at: "))
if "." in num1: # if "." is in the num it is a float
num1 = float(num1)
else: # else an int
num1 = int(num1)
if "." in num2:
num2 = float(num2)
else:
num2 = int(num2)
if "." in x:
x = float(x)
step=.5 # you will need more conditions to check and set the appropriate step.
else:
x = int(x)
step=1
print "Divisibility:"
for i in float_range(num1, num2 + 1,step=step): # add 1 to range to include top end of range
if i % x == 0:
print str(i) + ": Yes"
divisibility()
```

Similar Questions

Okay so, I have a column that looks something like this: 20140813000000000 It is displaying a date, in the format of decimal(17,0), but I need to take the first 8 characters out of it to convert it

I know how computer today stores negative integers, which most of the computers use the 2' complement. I just wast wondering the 2' complement method applies for all kinds of numbers like floating poi

Is there any function in Sql Server 2008 that controls scale numbers.For example if we have a decimal number 123.456 and in function if pass 0 it should return 123, if i pass 1 then should return 123.

This might seem like a simple question, but i have been strugling trying to come up with an easier answer to this problem. But still using grep. I want to grep out the positive (and negative numbers)

converter_scientific_notation_to_decimal_notation('1.34E-15') or converter_scientific_notation_to_decimal_notation(1.34E-15) => '0.00000000000000134' converter_scientific_notation_to_decimal_notati

I have a number of decimal numbers stored in a database and need to calculate the percentage increase(or decrease) between two of the numbers using PHP. An example of two of the numbers are: 111.0516

In my window application I need masked textbox which accept real decmal numbers. eg. 1) 1.56 2) 22.34 3) 123.34 4) 12312.34 This all value should be valid. Can anyone tell me how can I do this? And

In my projcet(WPF) textbox allow only positive and negative decimal numbers .I used Regular expression then it accepts -.values.but it is taking the values like this -123.-2 it is not correct.my requ

How can I split a list of integers to 2 lists: one of positive numbers and the other of negative numbers ? this is my attempt: is it possible to do it ? split:: [Int]->[[Int]] split [] =[[]] split

What's the cleanest, most effective way to validate decimal numbers in JavaScript? Bonus points for: Clarity. Solution should be clean and simple. Cross-platform. Test cases: 01. IsNumeric('-1') =&

I am looking for a convenient way to convert positive values (proportions) into negative values of the same variable, depending on the value of another variable. This is how the data structure looks l

I need a validation RegEx for decimal. It should allow up to 5 digits after decimal. Allow: 1 1.0 12.0 12.01 123.01 1,123.01 1,123.013 21,123.01234 3,21,123.01234 How Can I do regex for this?

I have a series of CSV files where numbers are formatted in the european style using commas instead of decimal points, i.e. 0,5 instead of 0.5. There are too many of these files to edit them before im

Since I started using eclipse for project euler, I noticed that big numbers sometime become a seemingly random negative numbers. I suppose this has something to do with passing the boudry of the type.

During my clojure studies, I found this: ;Clojure 1.4.0 (def neg_inf -1E-400) (cond (= neg_inf 0) Zero (< neg_inf 0) Negative (> neg_inf 0) Positive :default Neither ) ;#'user/neg_inf ;u

i'm trying to write a small java class. I have an object called BigNumber. I wrote method that add two positive numbers, and other method that subract two also positive numbers. Now i want them to ha

Possible Duplicate: Mod of negative number is melting my brain! I was wondering if there was a nicer algorithm for what I'm trying to do: wrapIndex(-6, 3) = 0 wrapIndex(-5, 3) = 1 wrapIndex(-4, 3)

I was implementing a routing algorithm in javascript, but when I assign a negative one variable in the array gives me this error: invalid array length. var node = new Array() node[0] = new Array(6,7)

i need a regular expression for decimal/float numbers like 12 12.2 1236.32 123.333 and +12.00 or -12.00 or ...123.123... for using in javascript and jQuery. Thank you.

I am trying to convert all negative numbers to positive numbers and have so far come up with this echo -32 45 -45 -72 | sed -re 's/\-([0-9])([0-9])\ /\1\2/p' but it is not working as it outputs: 3

I have a table gathering data from mysql. I use jquery to highlight the negative data in red. $(document).ready(function() { $('td').each(function() { var cellvalue = $(this).html(); if ( cellvalue.su

Using JSONObject to read a json response from a server. The server returns some decimal number. Normal numbers are not a problem to but the problem occurs when there is decimal number of form 0.00068.

New to java, i am trying to get output of variables grossPayConv, taxesConv and netPayConv to have the output of XX.XX(having 2 places after the decimal). i believe i am casting wrong or something. i

What started as a simple validation code converted in something very paradoxical in my eyes. The following code returns Good work! when I input a negative number in the InputBox popup Dim myvar As S

Guys I got a text box wherein users may enter valid decimal numbers. And later I have to do calculations with this decimal number without rounding it. Currently I am working as var pricePerItemExVat

This is the question. write a program that prompts the user to input five decimal numbers. the program should then add the five decimal numbers, convert the sum to the nearest integer,m and print the

how do i get the numbers after a decimal point? for example if i have 5.55 how do i get .55?

It is not working if it is decimal value comparison. Please debug the code and provide me the solution. Please find the below code Thanks in Advance.. i=2.4524 j=2.430 s=0.2 sub=`echo $i - $j | bc`

I am comparing lists of numbers and assigning scores for matching direction. Each match positive or negative should increase the participant's score by 1. For example: list1 =[5.6, -7.1, 6.4] list2

I try to query for numbers within a range, but I keep getting empty result if both numbers are < 0: max = float(request.vars.max) #-87 min = float(request.vars.min) #-90 qry1 = (max > db.db1.nbr

So, I made this code. Basically, takes in the number, then if negative, converts it to positive, calculates its binary and then its one complement and then adds 1. #include <stdio.h> int main (v

The function works fine with only positive number. Works sometimes with negative but most of the time show this error The value -1 is not of type UNSIGNED-BYTE. (defun OrdRapido (lista inf sup) (let

I need a program to convert Binary numbers into Decimal number in Java or in C++. is there some one who can help me.

I have a textbox which should allow user to enter only positive or negative decimal number with three decimal places. For Example: 73.345 or -2345.345 or -32.34. something like that. How to set the va

A variation of Searching in a Matrix that is sorted rowwise and columnwise Given a 2D Matrix that is sorted rowwise and columnwise. You have to return the count of negative numbers in most optimal w

This question already has an answer here: JavaScript displaying a float to 2 decimal places 3 answers So I made this quick script that calculates some numbers, but the answer ends with many dec

I would like to generate uniformly distributed random numbers between 0 and 0.5, but truncated to 2 decimal places. without the truncation, I know this is done by import numpy as np rs = np.random.Ran

So I am having a string that is created via function and then another function gets that string and takes only the numbers out of it. The string always looks like this (only the numbers change): rgba

I am trying to write recursive function which converts a binary numbers into decimal system. I couldn't find the bug. Any help will be appreciated deeply. Here is my first attempt: #include <iostre

I'm trying to design a script that given any arbitrary command-line input in euros and cents, calculate the change, using the minimum number of notes or coins. The script works fine with numbers with

I have one problem in BigDecimal with handling negative value in reverse order. I got a NumberFormatException. How can I solve it? This is my code: import java.math.BigDecimal; public class Java_bigde

I have always been coding in java and have recently started coding in javascript (node.js to be precise). One thing that's driving me crazy is add operation on decimal numbers; Consider the following

Could anyone help me for Regular expression for positive and a negative decimal value in objective c.

I have a form and I am using jquery validation plugin to validate it. Now I am trying to validate decimal number input. I have tried the following code, but its not working. Is the problem with the re

I've been making a linear equation calculator and I'm wondering how to let python use negative numbers. Like int(), float() etc... here is my code. import time print(Hello and welcome to the linear e

I want to convert double precision numbers to decimal . for example I have 23.43, the double value would be (using matlab) : 174 71 255 122 20 110 55 64 now having this how can I write a java program

My Edit text should accept only 3 digit number, not any other decimal numbers. I used below regular expression to do that but this is even accepting characters like . and -. So how to avoid accept

So I have this test program that checks the binary value of an integer one is positive and another is negative. int i = 100; int i2 = -100; System.out.println(Integer.toBinaryString(i)); System.out.pr

While executing this program on gcc, its working fine for positive numbers. but it should not crash for negative numbers as exception is handled. But its giving core dump. #include <iostream> us

I'm sure this is a simple problem, but I'm comparing negative numbers in javascript i.e.: var num1 = -83.778; var num2 = -83.356; if(num1 < num2) { // Take action 1 } else { // Take action 2 } Thi