Skip to content

Commit

Permalink
add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-develop committed Apr 5, 2022
1 parent 54042f0 commit 2157880
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/dice.noug
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# dice
# dice roll

import random
while True then
var input_ = input("'exit' to exit, anything else to roll a dice: ")
Expand Down
11 changes: 11 additions & 0 deletions examples/harmonic_mean.noug
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# harmonic mean between 2 numbers

def mean(x, y) -> (x + y) / 2

def harmonic_mean(x, y) -> 1 / mean(1/x, 1/y)

print("Harmonic mean between two numbers")
var x_ = input_int("Enter first number: ")
var y_ = input_int("Enter second number: ")

print(harmonic_mean(x_, y_))
11 changes: 11 additions & 0 deletions examples/pyramid_volume.noug
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# calculate the volume of a pyramid

def vol_pyramid(side, height)
var area = side ^ 2
return (1/3) * area * height
end

var side_ = input_int("Enter the side of the pyramid: ")
var height_ = input_int("Enter the height of the pyramid: ")

print(vol_pyramid(side_, height_))
10 changes: 10 additions & 0 deletions examples/reverse_string.noug
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# reverse a string

var string = input("Enter a string to reverse: ")
var new_string = ''

for letter in list(string) then
var new_string = letter + new_string
end

print(new_string)

0 comments on commit 2157880

Please sign in to comment.