From 8b808f1f857eba1b21e4dae5241da9be8ac2a899 Mon Sep 17 00:00:00 2001 From: Eric Douglas Date: Fri, 9 May 2014 22:00:28 -0300 Subject: [PATCH] examples.py and examples.js add - 01.01.02 --- .../02-core-elements-of-a-program/example.js | 21 ++++++++++++------- .../02-core-elements-of-a-program/example.py | 7 ++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/02-core-elements-of-a-program/example.js b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/02-core-elements-of-a-program/example.js index 9adec37..4ee9fac 100644 --- a/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/02-core-elements-of-a-program/example.js +++ b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/02-core-elements-of-a-program/example.js @@ -1,14 +1,21 @@ x = 3; // Create variable and assign value 3 to it - x = x * x; // Bind x to value 9 - console.log( x ); // print the x's value - process.stdout.write( 'Enter a number: ' ); // better way to print in the terminal process.stdin.resume(); -// convert the entered value from stream into a string +// convert the entered value from stream to a string // process.stdin.setEncoding( 'utf8' ); -process.stdin.on('data', function( inputText ) { - process.stdout.write( inputText.toString() ); - process.exit(); +var y = ''; +process.stdin.once('data', function( inputText ) { + y = inputText.toString(); + process.stdout.write( typeof y + '\n'); + process.stdout.write( y + '\n' ); + + process.stdout.write( 'Enter another number: ' ); + + process.stdin.once('data', function( inputText ) { + y = parseFloat( inputText.toString() ); + process.stdout.write( typeof y + '\n'); + process.stdout.write( y + '\n' ); + }); }); diff --git a/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/02-core-elements-of-a-program/example.py b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/02-core-elements-of-a-program/example.py index d27309f..5c0e526 100644 --- a/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/02-core-elements-of-a-program/example.py +++ b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/02-core-elements-of-a-program/example.py @@ -1,5 +1,10 @@ x = 3 # create variable x and assign value 3 to it x = x * x # bind x to value 9 print x -y = raw_input('enter a number:') +y = raw_input('enter a number: ') print type(y) +print y +y = float(raw_input('Enter a number: ')) +print type(y) +print y +print y * y