Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Practice nim exercises in narimiran.github.io/nim-basics/
- #Create an immutable variable containing your age (in years).
- #Print your age in days. (1 year = 365 days)
- const
- days = 365
- inches = 2.54
- let myage = 19 * days
- #Check if your age is divisible by 3
- echo myage
- echo myage mod 3 == 0
- #Create an immutable variable containing your height in centimeters #Print your height in inches (1 in = 2.54 cm)
- var myheight: float = 178
- echo myheight / inches
- #A pipe has a 3/8 inch diameter. Express the diameter in centimeters
- var pipe: float
- pipe = 3 / 8 * inches
- echo pipe
- #practice concat string
- var
- firstname = "Khuc"
- lastname = "Giang Sinh"
- let fullname = firstname & " " & lastname
- echo fullname
- #Is alice earn much money than bob ?
- const
- alice_earn_1 = 400 / 15
- bob_earn_1 = 3.14 * 8
- let bob_earn_30 = bob_earn_1 * 30
- let alice_earn_30 = alice_earn_1 * 30
- echo "Alice > Bob: ", alice_earn_30 > bob_earn_30
- #Collatz conjecture
- var n: int
- n = 11
- while n != 1:
- if (n mod 2 == 0):
- n = n div 2
- echo "n is even so n = n/2 = ", n
- else:
- n = 3 * n + 1
- echo "n is odd so n = 3n + 1 = ", n
- #Print all vowels in your full name
- for letter in fullname:
- case letter
- of 'u', 'e', 'o', 'a', 'i':
- echo letter
- else: discard
- #Fizz buzz game
- const
- fizz = "Fizz"
- buzz = "Buzz"
- for round in countup(1, 30, 1):
- if (round mod 3 == 0):
- if (round mod 5 == 0):
- echo fizz & buzz
- else:
- echo fizz
- elif (round mod 5 == 0):
- echo buzz
- else:
- echo round
- #Create a inches to centimeters conversion table
- echo "in\t" & "|\t" & "cm"
- echo "------------------"
- for i in 1..10:
- let cm = float(i) * inches
- echo i, '\t' & "|" & '\t', cm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement