M. Rocha
ROP Exploring Computer Science
Low level
High level
Script
In most cases the interpreter compiles the source code each time you run it. This is slow relative to the speed of compiled code.
Development times are significantly faster with interpreted programs
Execution times are usually faster for compiled programs
CUDA/OpenACC - Are extensions to C/C++ that allow you to program computing accelerators such as GPUs and Xeon Phi's
Arduino Language - Is a C/C++ extension that allows you to program arduino microcontrollers
JavaScript (C like)
Python
def main():
guessTheNumber(1, 100);
def guessTheNumber(low, high):
inclusive_range = (1, 100)
print("Guess the number between %i and %i.\n"
% inclusive_range)
target = random.randint(*inclusive_range)
answer, i = None, 0
while answer != target:
i += 1
txt = input("Your guess(%i): " % i)
try:
answer = int(txt)
except ValueError:
print(" I don't understand your input of '%s' ?" % txt)
continue
if answer < inclusive_range[0] or answer > inclusive_range[1]:
print(" Out of range!")
continue
if answer == target:
print(" You got it!")
break
if answer < target: print(" You're too low.")
if answer > target: print(" You're too high.")
print("\nThanks for playing.")
main()
function main() {
guessTheNumber(1, 100);
}
function guessTheNumber(low, high) {
var num = randOnRange(low, high);
function checkGuess(n) {
if (n < low || n > high) {
print('That number is not between ' + low + ' and ' + high + '!');
return false;
}
if (n == num) {
print("You got it!");
return true;
}
if (n < num) {
print("You're too low.");
} else {
print("You're too high.");
}
return false;
}
print('I have picked a number between ' + low + ' and ' + high + '. Try to guess it!');
while (true) {
putstr(" Your guess: ");
var n = parseInt(readline());
if (checkGuess(n)) break;
}
}
function randOnRange(low, high) {
var r = Math.random();
return Math.floor(r * (high - low + 1)) + low;
}
main();