Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #Practice nim exercises in narimiran.github.io/nim-basics/
  2. #Create an immutable variable containing your age (in years).
  3. #Print your age in days. (1 year = 365 days)
  4. const
  5. days = 365
  6. inches = 2.54
  7. let myage = 19 * days
  8. #Check if your age is divisible by 3
  9. echo myage
  10. echo myage mod 3 == 0
  11.  
  12. #Create an immutable variable containing your height in centimeters #Print your height in inches (1 in = 2.54 cm)
  13. var myheight: float = 178
  14. echo myheight / inches
  15. #A pipe has a 3/8 inch diameter. Express the diameter in centimeters
  16. var pipe: float
  17. pipe = 3 / 8 * inches
  18. echo pipe
  19.  
  20. #practice concat string
  21. var
  22. firstname = "Khuc"
  23. lastname = "Giang Sinh"
  24. let fullname = firstname & " " & lastname
  25. echo fullname
  26.  
  27. #Is alice earn much money than bob ?
  28. const
  29. alice_earn_1 = 400 / 15
  30. bob_earn_1 = 3.14 * 8
  31. let bob_earn_30 = bob_earn_1 * 30
  32. let alice_earn_30 = alice_earn_1 * 30
  33. echo "Alice > Bob: ", alice_earn_30 > bob_earn_30
  34.  
  35. #Collatz conjecture
  36. var n: int
  37. n = 11
  38. while n != 1:
  39. if (n mod 2 == 0):
  40. n = n div 2
  41. echo "n is even so n = n/2 = ", n
  42. else:
  43. n = 3 * n + 1
  44. echo "n is odd so n = 3n + 1 = ", n
  45.  
  46. #Print all vowels in your full name
  47. for letter in fullname:
  48. case letter
  49. of 'u', 'e', 'o', 'a', 'i':
  50. echo letter
  51. else: discard
  52.  
  53. #Fizz buzz game
  54. const
  55. fizz = "Fizz"
  56. buzz = "Buzz"
  57. for round in countup(1, 30, 1):
  58. if (round mod 3 == 0):
  59. if (round mod 5 == 0):
  60. echo fizz & buzz
  61. else:
  62. echo fizz
  63. elif (round mod 5 == 0):
  64. echo buzz
  65. else:
  66. echo round
  67.  
  68. #Create a inches to centimeters conversion table
  69. echo "in\t" & "|\t" & "cm"
  70. echo "------------------"
  71. for i in 1..10:
  72. let cm = float(i) * inches
  73. echo i, '\t' & "|" & '\t', cm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement