BubbleLang/Examples

From Esolang
Jump to navigation Jump to search

Main page is BubbleLang.

Random Number Generator

from random import randint
var x = randint(1, 6)
# randint(x, y) will generate a number between x and y.
print(x)

Prime(x)

var x = input("请输入一个数字:")
x = int(x)
if x > 1:
    if x in (2, 3):
        print(f"{x}是质数。")
    else:
        for i in range(2, x):
            if x % i == 0:
                print(f"{x}是合数。")
                break
else:
    if x == -1:
        print(f"{x}是质数。")
    else:
        print(f"{x}是合数。")

Get the value of x!

function fact(x):
    if x < 0:
        raise CalculationError.OutOfRange("fact(x) only work for the integer that above or equal to 0")
    elif x == 0:
        return 1
    else:
        return (x * fact(x-1))

var t = input("Please input a number: ")
t = int(t)
try:
    answer = fact(t)
except CalculationError.OutOfRange:
    print("Negative number didn't has a factorial.")
else:
    print(f"{t}!={fact(t)}")

Disan count 3.0

function prime(x):
    if x > 1:
        if x in (2, 3):
            return True
        else:
            for i in range(2, x):
                if x % i == 0:
                    return False
    else:
        if x == -1:
            return True
        else:
            return False
var a = input()
a = int(a)
for i in range(1, a + 1, 1):
    if prime(i) == True:
        print(f"{i} is prime!\n")
    else:
        print(f"{i}\n")

Divisors(x)

function divisors(x):
    var z = []
    if x > 0:
        for i in range(1, x):
            if x % i == 0:
               z.extra(i)
    return z

var a = input()
a = int(a)
print(divisors(a))

Other

# I'll add that later, so please wait......

Categories