by AI Code Generator

Popularity

3 out of 5 levels

about 30K users per month
Visit

Service information

Plans

freepaid

Requirements

social authemail requiredaccount registration required

Description

Refraction is an AI-powered code generation tool that can help you explain, convert, detect bugs, and refactor code in 56 different languages. Choose from Free or Paid plans and access the service via website or extension.

Examples

💻🔍

Explain Code

inputs

import random

number = random.randint(1, 10)

guess = None

while guess != number:

  guess = int(input("Guess a number between 1 and 10: "))

  if guess < number:

    print("Too low! Guess again.")

  elif guess > number:

    print("Too high! Guess again.")

print("Congratulations, you guessed the number", number, "correctly!")

outputs

This code is a simple guessing game.

First, it imports the random module, which allows the program to generate random numbers.

Then, it generates a random integer between 1 and 10 using the randint() function and assigns it to the variable number.

The variable guess is initialized to None.

The program then enters a while loop that will continue until the user correctly guesses the random number.

Within the loop, the program prompts the user to input a number between 1 and 10 using the input() function. The input is then converted to an integer using the int() function and assigned to the guess variable.

If the guess is lower than the random number, the program prints "Too low! Guess again." If the guess is higher than the random number, the program prints "Too high! Guess again."

If the guess is equal to the random number, the program exits the loop and prints "Congratulations, you guessed the number [number] correctly!" where [number] is the random number that was generated at the beginning of the program.

Overall, this code demonstrates the use of basic Python syntax, including variables, loops, conditional statements, and input/output functions.

Resources:

  • Python random module documentation: https://docs.python.org/3/library/random.html
  • Python input() function documentation: https://docs.python.org/3/library/functions.html#input
  • Python int() function documentation: https://docs.python.org/3/library/functions.html#int
💻🔀

Convert Code

inputs

import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    System.out.print("What is your name? ");

    String name = scanner.nextLine();

    System.out.print("How old are you? ");

    int age = scanner.nextInt();

    int yearsUntil100 = 100 - age;

    System.out.println("Hello, " + name + "!");

    System.out.println("You are " + age + " years old.");

    System.out.println("You will turn 100 in " + yearsUntil100 + " years.");

  }

}

outputs

# Python equivalent code

# There is no direct equivalent of java.util.Scanner in Python. We can use input() function instead.

print("What is your name? ")

name = input()

print("How old are you? ")

age = int(input())

yearsUntil100 = 100 - age

print("Hello, " + name + "!")

print("You are " + str(age) + " years old.")

print("You will turn 100 in " + str(yearsUntil100) + " years.")

💻🔄

Refactor Code

inputs

name = input("What is your name? ")

age = int(input("How old are you? "))

years_until_100 = 100 - age

print("Hello, " + name + "!")

print("You are " + str(age) + " years old.")

print("You will turn 100 in " + str(years_until_100) + " years.")

outputs

name = input("What is your name? ")

age = int(input("How old are you? "))

years_until_100 = 100 - age

print(f"Hello, {name}!")

print(f"You are {age} years old.")

print(f"You will turn 100 in {years_until_100} years.")

🔍🐛

Find Bug In Code

inputs

numbers = [1, 2, 3, 4, 5]

for i in range(len(numbers)):

    if numbers[i] % 2 == 0:

        numbers.pop(i)

print(numbers)

outputs

There is a bug in the code. When an even number is found in the list, the pop() method is used to remove it from the list. However, this changes the length of the list, which causes the loop to skip over the next number in the list. This means that some even numbers may not be removed from the list.

To fix this, we can iterate over the list in reverse order, so that removing an element does not affect the indices of the remaining elements. Here is the corrected code:

numbers = [1, 2, 3, 4, 5]

for i in range(len(numbers)-1, -1, -1):

if numbers[i] % 2 == 0:

numbers.pop(i)

print(numbers)

This code will correctly remove all even numbers from the list and print [1, 3, 5].

Features

  • Generates code using AI in 56 languages
  • Creates unit tests and documentation
  • Performs automated code refactoring
  • Integrates with OpenAI-powered AI models
  • Web-based tool that supports many languages like Java, Python, JavaScript, TypeScript, Ruby, Go, and more

Perfect for

  • Developers
Share this page: