WeixiangYan/CodeTransOcean huggingface dataset:
Task: Guess the number_With feedback



C#: using System;

class Program
{
    static void Main(string[] args)
    {
        const int from = 1;
        const int to = 10;

        int randomNumber = new Random().Next(from, to);
        int guessedNumber;

        Console.Write("The number is between {0} and {1}. ", from, to);
        while (true)
        {
            Console.Write("Make a guess: ");
            if (int.TryParse(Console.ReadLine(), out guessedNumber))
            {
                if (guessedNumber == randomNumber)
                {
                    Console.WriteLine("You guessed the right number!");
                    break;
                }
                else
                {
                    Console.WriteLine("Your guess was too {0}.", (guessedNumber > randomNumber) ? "high" : "low");
                }
            }
            else
            {
                Console.WriteLine("Input was not an integer.");
            }
        }

        Console.WriteLine();
        Console.WriteLine("Press any key to exit.");
        Console.ReadKey();
    }
}







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Guess-With-Feedback.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  Seed       PIC 9(8).
       01  Random-Num PIC 99.
       01  Guess      PIC 99.
 
       PROCEDURE DIVISION.
           ACCEPT Seed FROM TIME
           COMPUTE Random-Num =
               FUNCTION REM(FUNCTION RANDOM(Seed) * 1000, 10) + 1

           DISPLAY "Guess a number between 1 and 10:"
 
           PERFORM FOREVER
               ACCEPT Guess
 
               IF Guess > Random-Num
                   DISPLAY "Your guess was too high."
               ELSE IF Guess < Random-Num
                   DISPLAY "Your guess was too low."
               ELSE
                   DISPLAY "Well guessed!"
                   EXIT PERFORM
           END-PERFORM
 
           GOBACK
           .
Task: Guess the number_With feedback


C++: #include <iostream>
#include <cstdlib>
#include <ctime>

int main()
{
    std::srand(std::time(0));
    int lower, upper, guess;
    std::cout << "Enter lower limit: ";
    std::cin >> lower;
    std::cout << "Enter upper limit: ";
    std::cin >> upper;
    int random_number = lower + std::rand() % ((upper + 1) - lower);

    do
    {
        std::cout << "Guess what number I have: ";
        std::cin >> guess;
        if (guess > random_number)
            std::cout << "Your guess is too high\n";
        else if (guess < random_number)
            std::cout << "Your guess is too low\n";
        else
            std::cout << "You got it!\n";
    } while (guess != random_number);

    return 0;
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Guess-With-Feedback.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  Seed       PIC 9(8).
       01  Random-Num PIC 99.
       01  Guess      PIC 99.
 
       PROCEDURE DIVISION.
           ACCEPT Seed FROM TIME
           COMPUTE Random-Num =
               FUNCTION REM(FUNCTION RANDOM(Seed) * 1000, 10) + 1

           DISPLAY "Guess a number between 1 and 10:"
 
           PERFORM FOREVER
               ACCEPT Guess
 
               IF Guess > Random-Num
                   DISPLAY "Your guess was too high."
               ELSE IF Guess < Random-Num
                   DISPLAY "Your guess was too low."
               ELSE
                   DISPLAY "Well guessed!"
                   EXIT PERFORM
           END-PERFORM
 
           GOBACK
           .
Task: Guess the number_With feedback





Java: import java.util.Random;
import java.util.Scanner;
public class Main
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Random random = new Random();
        long from = 1;
        long to = 100;
        int randomNumber = random.nextInt(to - from + 1) + from;
        int guessedNumber = 0;

        System.out.printf("The number is between %d and %d.\n", from, to);

        do
        {
            System.out.print("Guess what the number is: ");
            guessedNumber = scan.nextInt();
            if (guessedNumber > randomNumber)
                System.out.println("Your guess is too high!");
            else if (guessedNumber < randomNumber)
                System.out.println("Your guess is too low!");
            else
                System.out.println("You got it!");
        } while (guessedNumber != randomNumber);
    }
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Guess-With-Feedback.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  Seed       PIC 9(8).
       01  Random-Num PIC 99.
       01  Guess      PIC 99.
 
       PROCEDURE DIVISION.
           ACCEPT Seed FROM TIME
           COMPUTE Random-Num =
               FUNCTION REM(FUNCTION RANDOM(Seed) * 1000, 10) + 1

           DISPLAY "Guess a number between 1 and 10:"
 
           PERFORM FOREVER
               ACCEPT Guess
 
               IF Guess > Random-Num
                   DISPLAY "Your guess was too high."
               ELSE IF Guess < Random-Num
                   DISPLAY "Your guess was too low."
               ELSE
                   DISPLAY "Well guessed!"
                   EXIT PERFORM
           END-PERFORM
 
           GOBACK
           .
Task: Guess the number_With feedback







Python: import random

inclusive_range = (1, 100)

print("Guess my target number that is between %i and %i (inclusive).\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("  Ye-Haw!!")
        break
    if answer < target: print("  Too low.")
    if answer > target: print("  Too high.")

print("\nThanks for playing.")



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Guess-With-Feedback.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  Seed       PIC 9(8).
       01  Random-Num PIC 99.
       01  Guess      PIC 99.
 
       PROCEDURE DIVISION.
           ACCEPT Seed FROM TIME
           COMPUTE Random-Num =
               FUNCTION REM(FUNCTION RANDOM(Seed) * 1000, 10) + 1

           DISPLAY "Guess a number between 1 and 10:"
 
           PERFORM FOREVER
               ACCEPT Guess
 
               IF Guess > Random-Num
                   DISPLAY "Your guess was too high."
               ELSE IF Guess < Random-Num
                   DISPLAY "Your guess was too low."
               ELSE
                   DISPLAY "Well guessed!"
                   EXIT PERFORM
           END-PERFORM
 
           GOBACK
           .
Task: Guess the number_With feedback








VB: Public Sub Main() 
  
  Randomize 
  Dim guess As Integer, max As Integer = 20 
  Dim n As Integer = Int(Rnd * max) + 1 
  
  Print "Guess which number I
  
  Do 
    Print " Your guess : "
    Input guess 
    If guess > n And guess <= 20 Then 
      Print "Your guess is higher than the chosen number, try again" 
    Else If guess = n Then 
      Print "Correct, well guessed!" 
      Break
    Else If guess < n And guess >= 1 Then 
      Print "Your guess is lower than the chosen number, try again" 
    Else 
      Print "Your guess is inappropriate, try again"    
    End If 
  Loop

End


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Guess-With-Feedback.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  Seed       PIC 9(8).
       01  Random-Num PIC 99.
       01  Guess      PIC 99.
 
       PROCEDURE DIVISION.
           ACCEPT Seed FROM TIME
           COMPUTE Random-Num =
               FUNCTION REM(FUNCTION RANDOM(Seed) * 1000, 10) + 1

           DISPLAY "Guess a number between 1 and 10:"
 
           PERFORM FOREVER
               ACCEPT Guess
 
               IF Guess > Random-Num
                   DISPLAY "Your guess was too high."
               ELSE IF Guess < Random-Num
                   DISPLAY "Your guess was too low."
               ELSE
                   DISPLAY "Well guessed!"
                   EXIT PERFORM
           END-PERFORM
 
           GOBACK
           .
Task: Guess the number_With feedback




Go: package main

import (
    "fmt"
    "math/rand"
    "time"
)

const lower, upper = 1, 100

func main() {
    fmt.Printf("Guess integer number from %d to %d: ", lower, upper)
    rand.Seed(time.Now().Unix())
    n := rand.Intn(upper-lower+1) + lower
    for guess := n; ; {
        switch _, err := fmt.Scan(&guess); {
        case err != nil:
            fmt.Println("\n", err, "So, bye.")
            return
        case guess < n:
            fmt.Print("Too low. Try again: ")
        case guess > n:
            fmt.Print("Too high. Try again: ")
        default:
            fmt.Println("Well guessed!")
            return
        }
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Guess-With-Feedback.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  Seed       PIC 9(8).
       01  Random-Num PIC 99.
       01  Guess      PIC 99.
 
       PROCEDURE DIVISION.
           ACCEPT Seed FROM TIME
           COMPUTE Random-Num =
               FUNCTION REM(FUNCTION RANDOM(Seed) * 1000, 10) + 1

           DISPLAY "Guess a number between 1 and 10:"
 
           PERFORM FOREVER
               ACCEPT Guess
 
               IF Guess > Random-Num
                   DISPLAY "Your guess was too high."
               ELSE IF Guess < Random-Num
                   DISPLAY "Your guess was too low."
               ELSE
                   DISPLAY "Well guessed!"
                   EXIT PERFORM
           END-PERFORM
 
           GOBACK
           .
Task: Guess the number_With feedback






PHP: <?php

session_start();

if(isset($_SESSION['number']))
{
   $number = $_SESSION['number'];
}
else
{
   $_SESSION['number'] = rand(1,10);
}


if($_POST["guess"]){
    $guess  = htmlspecialchars($_POST['guess']);

	echo $guess . "<br />";
    if ($guess < $number)
	{ 
        echo "Your guess is too low";
    }
	elseif($guess > $number)
	{
        echo "Your guess is too high";
    }
	elseif($guess == $number)
	{
        echo "You got the correct number!";
    }
    
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Guess A Number</title>
	</head>

	<body>
		<form action="<?=$_SERVER['PHP_SELF'] ?>" method="post" name="guess-a-number">
		    <label for="guess">Guess A Number:</label><br/ >
		    <input type="text" name="guess" />
		    <input name="number" type="hidden" value="<?= $number ?>" />
		    <input name="submit" type="submit" />
		</form>
	</body>
</html>
Task: Guess the number_With feedback






PHP: <?php

session_start();

if(isset($_SESSION['number']))
{
   $number = $_SESSION['number'];
}
else
{
   $_SESSION['number'] = rand(1,10);
}


if($_POST["guess"]){
    $guess  = htmlspecialchars($_POST['guess']);

	echo $guess . "<br />";
    if ($guess < $number)
	{ 
        echo "Your guess is too low";
    }
	elseif($guess > $number)
	{
        echo "Your guess is too high";
    }
	elseif($guess == $number)
	{
        echo "You got the correct number!";
    }
    
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Guess A Number</title>
	</head>

	<body>
		<form action="<?=$_SERVER['PHP_SELF'] ?>" method="post" name="guess-a-number">
		    <label for="guess">Guess A Number:</label><br/ >
		    <input type="text" name="guess" />
		    <input name="number" type="hidden" value="<?= $number ?>" />
		    <input name="submit" type="submit" />
		</form>
	</body>
</html>






Ada: with Ada.Numerics.Discrete_Random;
with Ada.Text_IO;
procedure Guess_Number_Feedback is
   function Get_Int (Prompt : in String) return Integer is
   begin
      loop
         Ada.Text_IO.Put (Prompt);
         declare
            Response : constant String := Ada.Text_IO.Get_Line;
         begin
            if Response /= "" then
               return Integer'Value (Response);
            end if;
         exception
            when others =>
               Ada.Text_IO.Put_Line ("Invalid response, not an integer!");
         end;
      end loop;
   end Get_Int;
   procedure Guess_Number (Lower_Limit : Integer; Upper_Limit : Integer) is
      subtype Number is Integer range Lower_Limit .. Upper_Limit;
      package Number_RNG is new Ada.Numerics.Discrete_Random (Number);
      Generator  : Number_RNG.Generator;
      My_Number  : Number;
      Your_Guess : Integer;
   begin
      Number_RNG.Reset (Generator);
      My_Number := Number_RNG.Random (Generator);
      Ada.Text_IO.Put_Line ("Guess my number!");
      loop
         Your_Guess := Get_Int ("Your guess: ");
         exit when Your_Guess = My_Number;
         if Your_Guess > My_Number then
            Ada.Text_IO.Put_Line ("Wrong, too high!");
         else
            Ada.Text_IO.Put_Line ("Wrong, too low!");
         end if;
      end loop;
      Ada.Text_IO.Put_Line ("Well guessed!");
   end Guess_Number;
   Lower_Limit : Integer;
   Upper_Limit : Integer;
begin
   loop
      Lower_Limit := Get_Int  ("Lower Limit: ");
      Upper_Limit := Get_Int  ("Upper Limit: ");
      exit when Lower_Limit < Upper_Limit;
      Ada.Text_IO.Put_Line ("Lower limit must be lower!");
   end loop;
   Guess_Number (Lower_Limit, Upper_Limit);
end Guess_Number_Feedback;
Task: Guess the number_With feedback






PHP: <?php

session_start();

if(isset($_SESSION['number']))
{
   $number = $_SESSION['number'];
}
else
{
   $_SESSION['number'] = rand(1,10);
}


if($_POST["guess"]){
    $guess  = htmlspecialchars($_POST['guess']);

	echo $guess . "<br />";
    if ($guess < $number)
	{ 
        echo "Your guess is too low";
    }
	elseif($guess > $number)
	{
        echo "Your guess is too high";
    }
	elseif($guess == $number)
	{
        echo "You got the correct number!";
    }
    
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>Guess A Number</title>
	</head>

	<body>
		<form action="<?=$_SERVER['PHP_SELF'] ?>" method="post" name="guess-a-number">
		    <label for="guess">Guess A Number:</label><br/ >
		    <input type="text" name="guess" />
		    <input name="number" type="hidden" value="<?= $number ?>" />
		    <input name="submit" type="submit" />
		</form>
	</body>
</html>




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Guess-With-Feedback.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       01  Seed       PIC 9(8).
       01  Random-Num PIC 99.
       01  Guess      PIC 99.
 
       PROCEDURE DIVISION.
           ACCEPT Seed FROM TIME
           COMPUTE Random-Num =
               FUNCTION REM(FUNCTION RANDOM(Seed) * 1000, 10) + 1

           DISPLAY "Guess a number between 1 and 10:"
 
           PERFORM FOREVER
               ACCEPT Guess
 
               IF Guess > Random-Num
                   DISPLAY "Your guess was too high."
               ELSE IF Guess < Random-Num
                   DISPLAY "Your guess was too low."
               ELSE
                   DISPLAY "Well guessed!"
                   EXIT PERFORM
           END-PERFORM
 
           GOBACK
           .
Task: Guess the number_With feedback








VB: Sub GuessTheNumberWithFeedback()
Dim Nbc&, Nbp&, m&, n&, c&

    Randomize Timer
    m = 11
    n = 100
    Nbc = Int((Rnd * (n - m + 1)) + m)
    Do
        c = c + 1
        Nbp = Application.InputBox("Choose a number between " & m & " and " & n & " : ", "Enter your guess", Type:=1)
        Select Case Nbp
            Case Is > Nbc: MsgBox "Higher than target!"
            Case Is < Nbc: MsgBox "Less than target!"
            Case Else: Exit Do
        End Select
    Loop
    MsgBox "Well guessed!" & vbCrLf & "You find : " & Nbc & " in " & c & " guesses!"
End Sub
Task: Compound data type



C#: struct Point
{
  public int x, y;
  public Point(int x, int y) {
    this.x = x;
    this.y = y;
  }
}









Ada: type Point is tagged record
   X : Integer := 0;
   Y : Integer := 0;
end record;
Task: Compound data type

C: typedef struct Point
{
  int x;
  int y;
} Point;











Ada: type Point is tagged record
   X : Integer := 0;
   Y : Integer := 0;
end record;
Task: Compound data type


C++: struct Point
{
  int x;
  int y;
};










Ada: type Point is tagged record
   X : Integer := 0;
   Y : Integer := 0;
end record;
Task: Compound data type




Go: type point struct {
    x, y float64
}








Ada: type Point is tagged record
   X : Integer := 0;
   Y : Integer := 0;
end record;
Task: Compound data type





Java: public class Point
{
  public int x, y;
  public Point() { this(0); }
  public Point(int x0) { this(x0,0); }
  public Point(int x0, int y0) { x = x0; y = y0; }

  public static void main(String args[])
  {
    Point point = new Point(1,2);
    System.out.println("x = " + point.x );
    System.out.println("y = " + point.y );
  }
}







Ada: type Point is tagged record
   X : Integer := 0;
   Y : Integer := 0;
end record;
Task: Compound data type







Python: X, Y = 0, 1
p = (3, 4)
p = [3, 4]

print p[X]





Ada: type Point is tagged record
   X : Integer := 0;
   Y : Integer := 0;
end record;
Task: Compound data type








VB: Type point
    x As Integer
    y As Integer
End Type




Ada: type Point is tagged record
   X : Integer := 0;
   Y : Integer := 0;
end record;
Task: Compound data type

C: typedef struct Point
{
  int x;
  int y;
} Point;
Task: Compound data type



C#: struct Point
{
  public int x, y;
  public Point(int x, int y) {
    this.x = x;
    this.y = y;
  }
}
Task: Compound data type





Java: public class Point
{
  public int x, y;
  public Point() { this(0); }
  public Point(int x0) { this(x0,0); }
  public Point(int x0, int y0) { x = x0; y = y0; }

  public static void main(String args[])
  {
    Point point = new Point(1,2);
    System.out.println("x = " + point.x );
    System.out.println("y = " + point.y );
  }
}
Task: Compound data type







Python: X, Y = 0, 1
p = (3, 4)
p = [3, 4]

print p[X]
Task: Compound data type


C++: struct Point
{
  int x;
  int y;
};
Task: Compound data type








VB: Type point
    x As Integer
    y As Integer
End Type
Task: Compound data type




Go: type point struct {
    x, y float64
}
Task: Compound data type



C#: struct Point
{
  public int x, y;
  public Point(int x, int y) {
    this.x = x;
    this.y = y;
  }
}








Fortran: program typedemo
    type rational                                           
        integer :: numerator
        integer :: denominator
    end type rational
    
    type( rational ), parameter :: zero = rational( 0, 1 )  
    type( rational ), parameter :: one  = rational( 1, 1 )  
    type( rational ), parameter :: half = rational( 1, 2 )
    integer :: n, halfd, halfn
    type( rational ) :: &
        one_over_n(20) = (/ (rational( 1, n ), n = 1, 20) /) 
                                                             
                                                             
    integer :: oon_denoms(20)                                
    
    halfd = half%denominator                       
    halfn = half%numerator
    
    oon_denoms = one_over_n%denominator            
                                                   
end program typedemo
Task: Compound data type


C++: struct Point
{
  int x;
  int y;
};









Fortran: program typedemo
    type rational                                           
        integer :: numerator
        integer :: denominator
    end type rational
    
    type( rational ), parameter :: zero = rational( 0, 1 )  
    type( rational ), parameter :: one  = rational( 1, 1 )  
    type( rational ), parameter :: half = rational( 1, 2 )
    integer :: n, halfd, halfn
    type( rational ) :: &
        one_over_n(20) = (/ (rational( 1, n ), n = 1, 20) /) 
                                                             
                                                             
    integer :: oon_denoms(20)                                
    
    halfd = half%denominator                       
    halfn = half%numerator
    
    oon_denoms = one_over_n%denominator            
                                                   
end program typedemo
Task: Compound data type

C: typedef struct Point
{
  int x;
  int y;
} Point;










Fortran: program typedemo
    type rational                                           
        integer :: numerator
        integer :: denominator
    end type rational
    
    type( rational ), parameter :: zero = rational( 0, 1 )  
    type( rational ), parameter :: one  = rational( 1, 1 )  
    type( rational ), parameter :: half = rational( 1, 2 )
    integer :: n, halfd, halfn
    type( rational ) :: &
        one_over_n(20) = (/ (rational( 1, n ), n = 1, 20) /) 
                                                             
                                                             
    integer :: oon_denoms(20)                                
    
    halfd = half%denominator                       
    halfn = half%numerator
    
    oon_denoms = one_over_n%denominator            
                                                   
end program typedemo
Task: Compound data type




Go: type point struct {
    x, y float64
}







Fortran: program typedemo
    type rational                                           
        integer :: numerator
        integer :: denominator
    end type rational
    
    type( rational ), parameter :: zero = rational( 0, 1 )  
    type( rational ), parameter :: one  = rational( 1, 1 )  
    type( rational ), parameter :: half = rational( 1, 2 )
    integer :: n, halfd, halfn
    type( rational ) :: &
        one_over_n(20) = (/ (rational( 1, n ), n = 1, 20) /) 
                                                             
                                                             
    integer :: oon_denoms(20)                                
    
    halfd = half%denominator                       
    halfn = half%numerator
    
    oon_denoms = one_over_n%denominator            
                                                   
end program typedemo
Task: Compound data type





Java: public class Point
{
  public int x, y;
  public Point() { this(0); }
  public Point(int x0) { this(x0,0); }
  public Point(int x0, int y0) { x = x0; y = y0; }

  public static void main(String args[])
  {
    Point point = new Point(1,2);
    System.out.println("x = " + point.x );
    System.out.println("y = " + point.y );
  }
}






Fortran: program typedemo
    type rational                                           
        integer :: numerator
        integer :: denominator
    end type rational
    
    type( rational ), parameter :: zero = rational( 0, 1 )  
    type( rational ), parameter :: one  = rational( 1, 1 )  
    type( rational ), parameter :: half = rational( 1, 2 )
    integer :: n, halfd, halfn
    type( rational ) :: &
        one_over_n(20) = (/ (rational( 1, n ), n = 1, 20) /) 
                                                             
                                                             
    integer :: oon_denoms(20)                                
    
    halfd = half%denominator                       
    halfn = half%numerator
    
    oon_denoms = one_over_n%denominator            
                                                   
end program typedemo