all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

View file

@ -0,0 +1,3 @@
{{selection|Short Circuit|Console Program Basics}}[[Category:Basic language learning]][[Category:Keyboard Input]] In this task, the goal is to input a string and the integer 75000, from the text console.
See also: [[User input/Graphical]]

View file

@ -0,0 +1,2 @@
---
note: Text processing

View file

@ -0,0 +1,5 @@
print("Enter a string: ");
STRING s := read string;
print("Enter a number: ");
INT i := read int;
~

View file

@ -0,0 +1,5 @@
~/src/opt/run $ awk 'BEGIN{printf "enter a string: "}{s=$0;i=$0+0;print "ok,"s"/"i}'
enter a string: hello world
ok,hello world/0
75000
ok,75000/75000

View file

@ -0,0 +1,14 @@
function Get_String return String is
Line : String (1 .. 1_000);
Last : Natural;
begin
Get_Line (Line, Last);
return Line (1 .. Last);
end Get_String;
function Get_Integer return Integer is
S : constant String := Get_String;
begin
return Integer'Value (S);
-- may raise exception Constraint_Error if value entered is not a well-formed integer
end Get_Integer;

View file

@ -0,0 +1,2 @@
My_String : String := Get_String;
My_Integer : Integer := Get_Integer;

View file

@ -0,0 +1,7 @@
DllCall("AllocConsole")
FileAppend, please type something`n, CONOUT$
FileReadLine, line, CONIN$, 1
msgbox % line
FileAppend, please type '75000'`n, CONOUT$
FileReadLine, line, CONIN$, 1
msgbox % line

View file

@ -0,0 +1,23 @@
TrayTip, Input:, Type a string:
Input(String)
TrayTip, Input:, Type an int:
Input(Int)
TrayTip, Done!, Input was recieved.
Msgbox, You entered "%String%" and "%Int%"
ExitApp
Return
Input(ByRef Output)
{
Loop
{
Input, Char, L1, {Enter}{Space}
If ErrorLevel contains Enter
Break
Else If ErrorLevel contains Space
Output .= " "
Else
Output .= Char
TrayTip, Input:, %Output%
}
}

View file

@ -0,0 +1,2 @@
INPUT "Enter a string"; s$
INPUT "Enter a number: ", i%

View file

@ -0,0 +1,5 @@
INPUT LINE "Enter a string: " string$
INPUT "Enter a number: " number
PRINT "String = """ string$ """"
PRINT "Number = " ; number

View file

@ -0,0 +1,3 @@
@echo off
set /p var=
echo %var%

View file

@ -0,0 +1,3 @@
<>:v:"Enter a string: "
^,_ >~:1+v
^ _@

View file

@ -0,0 +1,2 @@
<>:v:"Enter a number: "
^,_ & @

View file

@ -0,0 +1,16 @@
#include <iostream>
#include <string>
using namespace std;
int main()
{
// while probably all current implementations have int wide enough for 75000, the C++ standard
// only guarantees this for long int.
long int integer_input;
string string_input;
cout << "Enter an integer: ";
cin >> integer_input;
cout << "Enter a string: ";
cin >> string_input;
return 0;
}

View file

@ -0,0 +1 @@
cin >> string_input;

View file

@ -0,0 +1 @@
getline(cin, string_input);

View file

@ -0,0 +1,11 @@
#include <stdio.h>
int main(int argc, char* argv[])
{
int input;
if((scanf("%d", &input))==1)
{
printf("Read in %d\n", input);
return 1;
}
return 0;
}

View file

@ -0,0 +1,4 @@
(import '(java.util Scanner))
(def scan (Scanner. *in*))
(def s (.nextLine scan))
(def n (.nextInt scan))

View file

@ -0,0 +1,9 @@
(format t "Enter some text: ")
(let ((s (read-line)))
(format t "You entered ~s~%" s))
(format t "Enter a number: ")
(let ((n (read)))
(if (numberp n)
(format t "You entered ~d.~%" n)
(format t "That was not a number.")))

View file

@ -0,0 +1,13 @@
import std.stdio;
void main() {
long number;
write("Enter an integer: ");
readf("%d", &number);
char[] str;
write("Enter a string: ");
readf(" %s\n", &str);
writeln("Read in '", number, "' and '", str, "'");
}

View file

@ -0,0 +1,22 @@
program UserInputText;
{$APPTYPE CONSOLE}
uses SysUtils;
var
s: string;
lStringValue: string;
lIntegerValue: Integer;
begin
WriteLn('Enter a string:');
Readln(lStringValue);
repeat
WriteLn('Enter the number 75000');
Readln(s);
lIntegerValue := StrToIntDef(s, 0);
if lIntegerValue <> 75000 then
Writeln('Invalid entry: ' + s);
until lIntegerValue = 75000;
end.

View file

@ -0,0 +1,2 @@
{ok, [String]} = io:fread("Enter a string: ","~s").
{ok, [Number]} = io:fread("Enter a number: ","~d").

View file

@ -0,0 +1 @@
String = io:get_line("Enter a string: ").

View file

@ -0,0 +1,9 @@
include get.e
sequence s
atom n
s = prompt_string("Enter a string:")
puts(1, s & '\n')
n = prompt_number("Enter a number:",{})
printf(1, "%d", n)

View file

@ -0,0 +1,3 @@
[[^$' =~][,]#,]w:
[0[^'0-$$9>0@>|~][\10*+]#%]d:
w;! d;!.

View file

@ -0,0 +1,4 @@
"Enter a string: " write
readln
"Enter a number: " write
readln string>number

View file

@ -0,0 +1,4 @@
printl("Enter a string:")
str = input()
printl("Enter a number:")
n = int(input())

View file

@ -0,0 +1,18 @@
class Main
{
public static Void main ()
{
Env.cur.out.print ("Enter a string: ").flush
str := Env.cur.in.readLine
echo ("Entered :$str:")
Env.cur.out.print ("Enter 75000: ").flush
Int n
try n = Env.cur.in.readLine.toInt
catch (Err e)
{
echo ("You had to enter a number")
return
}
echo ("Entered :$n: which is " + ((n == 75000) ? "correct" : "wrong"))
}
}

View file

@ -0,0 +1,3 @@
: INPUT$ ( n -- addr n )
PAD SWAP ACCEPT
PAD SWAP ;

View file

@ -0,0 +1,4 @@
: INPUT# ( -- u true | false )
0. 16 INPUT$ DUP >R
>NUMBER NIP NIP
R> <> DUP 0= IF NIP THEN ;

View file

@ -0,0 +1,2 @@
: INPUT# ( -- n true | d 1 | false )
16 INPUT$ SNUMBER? ;

View file

@ -0,0 +1,3 @@
: INPUT# ( -- n true | false )
16 INPUT$ NUMBER? NIP
DUP 0= IF NIP THEN ;

View file

@ -0,0 +1,8 @@
: input#
begin
refill drop bl parse-word ( a n)
number error? ( n f)
while ( n)
drop ( --)
repeat ( n)
;

View file

@ -0,0 +1,6 @@
: TEST
." Enter your name: " 80 INPUT$ CR
." Hello there, " TYPE CR
." Enter a number: " INPUT# CR
IF ." Your number is " .
ELSE ." That's not a number!" THEN CR ;

View file

@ -0,0 +1,7 @@
character(20) :: s
integer :: i
print*, "Enter a string (max 20 characters)"
read*, s
print*, "Enter the integer 75000"
read*, i

View file

@ -0,0 +1,2 @@
s = input["Enter a string: "]
i = parseInt[input["Enter an integer: "]]

View file

@ -0,0 +1,13 @@
package main
import "fmt"
func main() {
var s string
var i int
if _, err := fmt.Scan(&s, &i); err == nil && i == 75000 {
fmt.Println("good")
} else {
fmt.Println("wrong")
}
}

View file

@ -0,0 +1,38 @@
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
in := bufio.NewReader(os.Stdin)
fmt.Print("Enter string: ")
s, err := in.ReadString('\n')
if err != nil {
fmt.Println(err)
return
}
s = strings.TrimSpace(s)
fmt.Print("Enter 75000: ")
s, err = in.ReadString('\n')
if err != nil {
fmt.Println(err)
return
}
n, err := strconv.Atoi(strings.TrimSpace(s))
if err != nil {
fmt.Println(err)
return
}
if n != 75000 {
fmt.Println("fail: not 75000")
return
}
fmt.Println("Good")
}

View file

@ -0,0 +1,2 @@
word = System.in.readLine()
num = System.in.readLine().toInteger()

View file

@ -0,0 +1,9 @@
import System.IO (hFlush, stdout)
main = do
putStr "Enter a string: "
hFlush stdout
str <- getLine
putStr "Enter an integer: "
hFlush stdout
num <- readLn :: IO Int
putStrLn $ str ++ (show num)

View file

@ -0,0 +1,10 @@
procedure main ()
writes ("Enter something: ")
s := read ()
write ("You entered: " || s)
writes ("Enter 75000: ")
if (i := integer (read ())) then
write (if (i = 75000) then "correct" else "incorrect")
else write ("you must enter a number")
end

View file

@ -0,0 +1,2 @@
string := File clone standardInput readLine("Enter a string: ")
integer := File clone standardInput readLine("Enter 75000: ") asNumber

View file

@ -0,0 +1,3 @@
require 'misc' NB. load system script
prompt 'Enter string: '
0".prompt 'Enter an integer: '

View file

@ -0,0 +1,14 @@
prompt 'Enter string: ' NB. output string to session
Enter string: Hello World
Hello World
0".prompt 'Enter an integer: ' NB. output integer to session
Enter an integer: 75000
75000
mystring=: prompt 'Enter string: ' NB. store string as noun
Enter string: Hello Rosetta Code
myinteger=: 0".prompt 'Enter an integer: ' NB. store integer as noun
Enter an integer: 75000
mystring;myinteger NB. show contents of nouns
┌──────────────────┬─────┐
│Hello Rosetta Code│75000│
└──────────────────┴─────┘

View file

@ -0,0 +1,10 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class GetInput {
public static void main(String[] args) throws Exception {
BufferedReader sysin = new BufferedReader(new InputStreamReader(System.in));
int number = Integer.parseInt(sysin.readLine());
String string = sysin.readLine();
}
}

View file

@ -0,0 +1,9 @@
import java.util.Scanner;
public class GetInput {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
String string = stdin.nextLine();
int number = stdin.nextInt();
}
}

View file

@ -0,0 +1,8 @@
WScript.Echo("Enter a string");
var str = WScript.StdIn.ReadLine();
var val = 0;
while (val != 75000) {
WScript.Echo("Enter the integer 75000");
val = parseInt( WScript.StdIn.ReadLine() );
}

View file

@ -0,0 +1,8 @@
print("Enter a string");
var str = readline();
var val = 0;
while (val != 75000) {
print("Enter the integer 75000");
val = parseInt( readline() );
}

View file

@ -0,0 +1,4 @@
"Enter a string: " putchars
stdin fgets
"Enter a number: " putchars
stdin fgets 10 strtol.

View file

@ -0,0 +1,2 @@
System.file.stdout|write("Enter a String ");
string = System.file.stdin|readline();

View file

@ -0,0 +1,2 @@
Input "Enter a string. ";string$
Input "Enter the value 75000.";num

View file

@ -0,0 +1,7 @@
make "input readlist ; in: string 75000
show map "number? :input ; [false true]
make "input readword ; in: 75000
show :input + 123 ; 75123
make "input readword ; in: string 75000
show :input ; string 75000

View file

@ -0,0 +1,4 @@
print('Enter a string: ')
s = io.stdin:read()
print('Enter a number: ')
i = tonumber(io.stdin:read())

View file

@ -0,0 +1,20 @@
>> input('Input string: ')
Input string: 'Hello'
ans =
Hello
>> input('Input number: ')
Input number: 75000
ans =
75000
>> input('Input number, the number will be stored as a string: ','s')
Input number, the number will be stored as a string: 75000
ans =
75000

View file

@ -0,0 +1,8 @@
TXTINP
NEW S,N
WRITE "Enter a string: "
READ S,!
WRITE "Enter the number 75000: "
READ N,!
KILL S,N
QUIT

View file

@ -0,0 +1,2 @@
mystring = InputString["give me a string please"];
myinteger = Input["give me an integer please"];

View file

@ -0,0 +1,12 @@
string s;
message "write a string: ";
s := readstring;
message s;
message "write a number now: ";
b := scantokens readstring;
if b = 750:
message "You've got it!"
else:
message "Sorry..."
fi;
end

View file

@ -0,0 +1,3 @@
s = System.console.readLine()
puts s

View file

@ -0,0 +1,14 @@
MODULE Input EXPORTS Main;
IMPORT IO, Fmt;
VAR string: TEXT;
number: INTEGER;
BEGIN
IO.Put("Enter a string: ");
string := IO.GetLine();
IO.Put("Enter a number: ");
number := IO.GetInt();
IO.Put("You entered: " & string & " and " & Fmt.Int(number) & "\n");
END Input.

View file

@ -0,0 +1,20 @@
using System;
using System.Console;
module Input
{
Main() : void
{
Write("Enter a string:");
_ = ReadLine()
mutable entry = 0;
mutable numeric = false;
do
{
Write("Enter 75000:");
numeric = int.TryParse(ReadLine(), out entry);
} while ((!numeric) || (entry != 75000))
}
}

View file

@ -0,0 +1,17 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
checkVal = 75000
say 'Input a string then the number' checkVal
parse ask inString
parse ask inNumber .
say 'Input string:' inString
say 'Input number:' inNumber
if inNumber == checkVal then do
say 'Success! Input number is as requested'
end
else do
say 'Failure! Number' inNumber 'is not' checkVal
end
return

View file

@ -0,0 +1,5 @@
print_string "Enter a string: ";
let str = read_line () in
print_string "Enter an integer: ";
let num = read_int () in
Printf.printf "%s%d\n" str num

View file

@ -0,0 +1,13 @@
use IO;
bundle Default {
class Hello {
function : Main(args : String[]) ~ Nil {
string := Console->GetInstance()->ReadString();
string->PrintLine();
number := Console->GetInstance()->ReadString()->ToInt();
number->PrintLine();
}
}
}

View file

@ -0,0 +1,15 @@
% read a string ("s")
s = input("Enter a string: ", "s");
% read a GNU Octave expression, which is evaluated; e.g.
% 5/7 gives 0.71429
i = input("Enter an expression: ");
% parse the input for an integer
printf("Enter an integer: ");
ri = scanf("%d");
% show the values
disp(s);
disp(i);
disp(ri);

View file

@ -0,0 +1,14 @@
declare
StdIn = {New class $ from Open.file Open.text end init(name:stdin)}
StringInput
Num = {NewCell 0}
in
{System.printInfo "Enter a string: "}
StringInput = {StdIn getS($)}
for until:@Num == 75000 do
{System.printInfo "Enter 75000: "}
Line = {StdIn getS($)}
in
Num := try {String.toInt Line} catch _ then 0 end
end

View file

@ -0,0 +1,2 @@
s=input();
n=eval(input());

View file

@ -0,0 +1,4 @@
#!/usr/bin/php
<?php
$string = fgets(STDIN);
$integer = (int) fgets(STDIN);

View file

@ -0,0 +1,11 @@
declare s character (100) varying;
declare k fixed decimal (15);
put ('please type a string:');
get edit (s) (L);
put skip list (s);
put skip list ('please type the integer 75000');
get list (k);
put skip list (k);
put skip list ('Thanks');

View file

@ -0,0 +1,9 @@
program UserInput(input, output);
var i : Integer;
s : String;
begin
write('Enter an integer: ');
readln(i);
write('Enter a string: ');
readln(s)
end.

View file

@ -0,0 +1,2 @@
my $str = prompt("Enter a string: ");
my $int = prompt("Enter a integer: ");

View file

@ -0,0 +1,4 @@
#!/usr/bin/perl
my $string = <>; # equivalent to readline(*STDIN)
my $integer = <>;

View file

@ -0,0 +1,4 @@
(in NIL # Guarantee reading from standard input
(let (Str (read) Num (read))
(prinl "The string is: \"" Str "\"")
(prinl "The number is: " Num) ) )

View file

@ -0,0 +1,6 @@
int main(){
write("Enter a String: ");
string str = Stdio.stdin->gets();
write("Enter 75000: ");
int num = Stdio.stdin->gets();
}

View file

@ -0,0 +1,9 @@
;;; Setup item reader
lvars itemrep = incharitem(charin);
lvars s, c, j = 0;
;;; read chars up to a newline and put them on the stack
while (charin() ->> c) /= `\n` do j + 1 -> j ; c endwhile;
;;; build the string
consstring(j) -> s;
;;; read the integer
lvars i = itemrep();

View file

@ -0,0 +1,6 @@
%open stdin for reading (and name the channel "kbd"):
/kbd (%stdin) (r) file def
%make ten-char buffer to read string into:
/buf (..........) def
%read string into buffer:
kbd buf readline

View file

@ -0,0 +1,2 @@
%if the read was successful, convert the string to integer:
{cvi} if

View file

@ -0,0 +1,2 @@
$string = Read-Host "Input a string"
[int]$number = Read-Host "Input a number"

View file

@ -0,0 +1,16 @@
If OpenConsole()
; Declare a string and a integer to be used
Define txt.s, num.i
Print("Enter a string: ")
txt=Input()
Repeat
Print("Enter the number 75000: ")
num=Val(Input()) ; Converts the Input to a Value with Val()
Until num=75000
; Check that the user really gives us 75000!
Print("You made it!")
Delay(3000): CloseConsole()
EndIf

View file

@ -0,0 +1 @@
string = raw_input("Input a string: ")

View file

@ -0,0 +1 @@
string = input("Input a string: ")

View file

@ -0,0 +1 @@
number = input("Input a number: ") # Deprecated, please don't use.

View file

@ -0,0 +1 @@
number = eval(input("Input a number: ")) # Evil, please don't use.

View file

@ -0,0 +1 @@
number = float(raw_input("Input a number: "))

View file

@ -0,0 +1 @@
number = float(input("Input a number: "))

View file

@ -0,0 +1,2 @@
stringval <- readline("String: ")
intval <- as.integer(readline("Integer: "))

View file

@ -0,0 +1,29 @@
REBOL [
Title: "Textual User Input"
Author: oofoe
Date: 2009-12-07
URL: http://rosettacode.org/wiki/User_Input_-_text
]
s: n: ""
; Because I have several things to check for, I've made a function to
; handle it. Note the question mark in the function name, this convention
; is often used in Forth to indicate test of some sort.
valid?: func [s n][
error? try [n: to-integer n] ; Ignore error if conversion fails.
all [0 < length? s 75000 = n]]
; I don't want to give up until I've gotten something useful, so I
; loop until the user enters valid data.
while [not valid? s n][
print "Please enter a string, and the number 75000:"
s: ask "string: "
n: ask "number: "
]
; It always pays to be polite...
print rejoin [ "Thank you. Your string was '" s "'."]

View file

@ -0,0 +1,11 @@
/*REXX program gets a string and the number 75000 from the console. */
say 'Please enter a text string:' /*show prompt for a text string. */
parse pull userString /*get the user text and store it.*/
do until userNumber=75000 /*repeat until correct.*/
say /*display a blank line.*/
say 'Please enter the number 75000' /*show the nice prompt.*/
parse pull userNumber /*get the user text. */
end /*until*/ /*now, check if it's OK*/
/*stick a fork in it, we're done.*/

View file

@ -0,0 +1,8 @@
import util::IDE;
public void InputConsole(){
x = "";
createConsole("Input Console",
"Welcome to the Input Console\nInput\> ",
str (str inp) {x = "<inp == "75000" ? "You entered 75000" : "You entered a string">";
return "<x>\n<inp>\nInput\>";});
}

View file

@ -0,0 +1,2 @@
'Input a string: ' print expect as str
'Input an integer: ' print expect 0 prefer as num

View file

@ -0,0 +1,6 @@
: example ( "- )
remapping off
"Enter a string: " puts 10 accept tib tempString
[ "Enter 75000: " puts getToken toNumber 75000 = cr ] until
"Your string was: '%s'\n" puts
remapping on ;

View file

@ -0,0 +1,6 @@
print "Enter a string: "
s = gets
print "Enter an integer: "
i = gets.to_i # If string entered, will return zero
puts "String = #{s}"
puts "Integer = #{i}"

View file

@ -0,0 +1,6 @@
output = "Enter a string:"
str = trim(input)
output = "Enter an integer:"
int = trim(input)
output = "String: " str " Integer: " int
end

View file

@ -0,0 +1,4 @@
print("Enter a number: ")
val i=Console.readInt
print("Enter a string: ")
val s=Console.readLine

View file

@ -0,0 +1,4 @@
(define str (read))
(define num (read))
(display "String = ") (display str)
(display "Integer = ") (display num)

View file

@ -0,0 +1,12 @@
$ include "seed7_05.s7i";
const proc: main is func
local
var integer: integer_input is 0;
var string: string_input is "";
begin
write("Enter an integer: ");
readln(integer_input);
write("Enter a string: ");
readln(string_input);
end func;

View file

@ -0,0 +1,7 @@
print: (query: 'Enter a String: ').
[| n |
n: (Integer readFrom: (query: 'Enter an Integer: ')).
(n is: Integer)
ifTrue: [print: n]
ifFalse: [inform: 'Not an integer: ' ; n printString]
] do.

View file

@ -0,0 +1,5 @@
'Enter a number: ' display.
a := stdin nextLine asInteger.
'Enter a string: ' display.
b := stdin nextLine.

View file

@ -0,0 +1,7 @@
print "Enter a string: ";
let val str = valOf (TextIO.inputLine TextIO.stdIn) in (* note: this keeps the trailing newline *)
print "Enter an integer: ";
let val num = valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn) in
print (str ^ Int.toString num ^ "\n")
end
end

View file

@ -0,0 +1,6 @@
:Input "Enter a string:",Str1
:Prompt i
:If(i ≠ 75000): Then
:Disp "That isn't 75000"
:Else
:Stop

View file

@ -0,0 +1,11 @@
Prgm
InputStr "Enter a string", s
Loop
Prompt integer
If integer ≠ 75000 Then
Disp "That wasn't 75000."
Else
Exit
EndIf
EndLoop
EndPrgm

Some files were not shown because too many files have changed in this diff Show more