-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.txt
125 lines (98 loc) · 2.16 KB
/
input.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
print("Hello World")
x=3
name="Bob"
y=str(3*27)
int("3")
float("3.14")
print(x)
print(y)
print(name)
function triple(number)
return number*3
endfunction
y=triple(7)
print(y)
// Arrays
array names[5]
names[0]="Ahmad"
names[1]="Ben"
names[2]="Catherine"
names[3]="Dan"
names[4]="Elijah"
print(names[3])
// Multidimensional arrays
Array board[8,8]
board[0,0]="rook"
// print(board[0,0])
entry=input("Please enter your name")
if entry=="Harsh" then
print("You selected Harsh") // That's me
elseif entry=="B" then
print("You selected B")
else
print("Unrecognised selection")
endif
// Procedures are pretty similar to functions tbh
procedure greeting(name)
print("anyway, hello "+name)
endprocedure
greeting(entry)
someText="Computer Science"
print(someText.length)
print(someText.substring(3,3))
// For loops might be tricky
for i=0 to 7
print(i)
next i
do
answer=input("What is the answer to life, the universe and everything?")
until answer=="42"
while (x MOD 10 <= 5)
print(x)
x = x + 1
endwhile
print()
print("Counting from given input to 0")
procedure countDownFrom(number)
while(number > 0)
print(number)
number = number - 1
endwhile
endprocedure
// TODO: Below line is not working
//countDownAmount = int(input("So... enter that number"))
countDownAmount = 20
countDownFrom(countDownAmount)
print()
// Logical operators
// Note: XOR is AB' + A'B, since I want to test AND, OR and NOT this works out
function xor(a, b)
return ((a AND NOT(b)) OR (NOT(a) AND b))
endfunction
print(xor(true, true))
something = input("Enter anything")
switch something:
case "A":
print("You picked A")
case "42":
print("#Douglas Adams")
default:
print("You are a slave to the system")
endswitch
// File IO
myFile = openRead("sample-read.txt")
x = myFile.readLine()
myFile.close()
print("First line below")
print(x)
print()
myFile = openRead("sample-read.txt")
while NOT myFile.endOfFile()
print(myFile.readLine())
endwhile
myFile.close()
print()
print()
myFile = openWrite("sample-write.txt")
myFile.writeLine("THIS IS A SAMPLE TEXT FILE CREATED TO SHOW THE WRITE FUNCTIONALITY")
myFile.close()