This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#accept a number, and return its binary form | |
x = float(raw_input('Enter a number: ')) | |
isNeg = False | |
if x < 0: | |
x = abs(x) | |
isNeg = True | |
resultInt = '' | |
resultFlt = '' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = float(raw_input('Enter a number between 0 and 1: ')) | |
p = 0 | |
#if a number is a whole number, the reminder when divided by 1 is always 0 | |
#if a number is not a whole number, the reminder when divided by 1 is NOT 0 | |
#Because we are trying to convert a decimal to a whole number, this check is necessary | |
while (((2**p) * x)%1 !=0): | |
print('Remainder = ' + str((2**p)*x - int((2**p)*x))) | |
p += 1 | |
num = int(x*(2**p)) | |
print str(p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = float(raw_input('Enter any number (decimal or integer)')) | |
if (x%1 ==0): | |
print('Whole number') | |
else: | |
print('Not a whole number') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = float(raw_input('Enter a decimal number: ')) | |
a = int(x) | |
c = (float(a + (a+1))/2) | |
#print ('c = ' + str(c)) | |
if x >= c: | |
b = int(x) + 1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = int(raw_input('enter an int: ')) | |
isNeg = False | |
if x < 0: | |
x = abs(x) | |
isNeg = True | |
result ='' | |
if x == 0: | |
result = '0' | |
while x>0: | |
result = str(x%2) + result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class FindWithinHorizon_Test { | |
public static void main(String args[]) { | |
Scanner myScanner = new Scanner(System.in); | |
char t,x; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class AssignmentOperators { | |
public static void main(String args[]) { | |
int k = 5; | |
double d; | |
Scanner myScanner = new Scanner(System.in); | |
System.out.println("select the assignment operator you want to use: \n" + "1. addition\n" + "2. substraction\n" + "3. multiplication \n" + "4. division \n"); |
NewerOlder