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"); |
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
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
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 = 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 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
#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
def clip(lo, x, hi): | |
''' | |
Takes in three numbers and returns a value based on the value of x. | |
Returns: | |
- lo, when x < lo | |
- hi, when x > hi | |
- x, otherwise | |
''' | |
# Your code here | |
return min(max(x,lo),hi) |
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
def odd(x): | |
''' | |
x: int or float. | |
returns: True if x is odd, False otherwise | |
''' | |
# Your code here | |
y = x%2 | |
return bool(y) |
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
def isVowel(char): | |
''' | |
char: a single letter of any case | |
returns: True if char is a vowel and False otherwise. | |
''' | |
# Your code here | |
if ((char =='a') or (char=='e') or (char == 'i') or (char == 'o') or (char =='u')): | |
return True | |
elif ((char =='A') or (char=='E') or (char == 'I') or (char == 'O') or (char =='U')): |
OlderNewer