Skip to main content

Examples

Example in Python#

User's request :

Calculate factorial of number given by user

Code generated by SourceAI :

import math
print("Enter a number: ")
num = int(input())
factorial_number = 1
for i in range(1, num + 1):
factorial_number *= i
print(factorial_number)

Example in Java#

User's request :

Write a method that returns the nth element of the Fibonacci Sequence

Code generated by SourceAI :

public Integer fibonacci(Integer n) {
if (n == 1) {
return 1;
} else if (n == 0) {
return 0;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}

Example in SQL#

User's request :

Select the title of the movies table where director_id is 'Brenda Chapman'
from directors table

Code generated by SourceAI :

SELECT title
FROM 'movies'
WHERE director_id
IS (SELECT id FROM 'directors' WHERE name is 'Brenda Chapman')

Example 2: Simplify (Refactoring code)#

User's request :

from collections import Counter
def count_ab(string):
string = string.lower()
counts = Counter(string)
if counts['a'] == counts['b']:
return True
else:
return False

Code generated by SourceAI :

def count_ab(str):
str = str.lower()
return str.count['a'] == str.count['b']

Example 3: Generating Commands for Kali Linux Tools (For Ethical Hackers & Bug Bounty Hunters)#

User's request :

Scan the remote host 192.168.0.1 for the specific ports 22 & 80 with TCP ACK ping

Command generated by SourceAI:

nmap -PA -p 22,80 192.168.0.1

Example 4: Debugger#

User's request :

ValueError: could not convert string to float: 'string'

Answer generated by SourceAI:

You are trying to convert a string to a float.
You need to check your code and make sure that you have passed the correct data type.
You should be able to convert strings that look like floats to floats by just using
float(mystr).

Example 5: Syntax Error fixing#

User's request :

msg = 'don't'
print("Hello World!)
print(msg)

Code generated by SourceAI :

msg = "don't"
print("Hello World!")
print(msg)

Example 6: Generating code with a README file (if you don't have any coding knowledge)#

User's request :

Make a simple calculator

Code generated by SourceAI :

def add(x, y):
return x + y
def subtract(x, y):
return x - y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
choice = input("Enter choice(1/2/3/4): ")
if choice in ('1', '2', '3', '4'):
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
elif choice == '2':
print(num1, "-", num2, "=", subtract(num1, num2))
elif choice == '3':
print(num1, "*", num2, "=", multiply(num1, num2))
elif choice == '4':
print(num1, "/", num2, "=", divide(num1, num2))
break
else:
print("Invalid Input")

README file generated by SourceAI :

Download the generated python file.
Prerequisites :
To run this function you need Python.
If you already have python installed, please skip to the next step.
You can install Python here: https://www.python.org/downloads/
Installation of dependencies:
To run this function you do not need any other dependencies.
To run it, open a terminal and type "python" then drag and drop the file as below:
`python calculator.py`