print("hello IXD-256!")
print(1+1*2)
# variable example:
x = 2
print(x)
# for loop example:
for i in range(3):
print('i =', i)
# while loop example:
while x < 4:
print('x =', x)
x += 1 # increment x
print('is x less than 4?', x < 4)
# if, elif, else conditions example:
x = 0
if x > 0:
print('x is positive')
elif x < 0:
print('x is negative')
else:
print('x is zero')
# function definition example:
def print_hello():
print('hello')
print_hello()
# function definition with one parameter:
def print_something(x):
print('x =', x)
print_something(x = 256)
print_something('ixd-256')
# function with a local variable:
def my_function():
local_variable = 1
print('local_variable =', local_variable)
my_function()
# print('local_variable =', local_variable) # ERROR
# can't use local variable outside the function
# eample of a global variable:
global_variable = 0
# function that uses a global variable:
def my_function():
# tell the function to use the global variable:
global global_variable
global_variable = 1
print('global_variable =', global_variable)
my_function()
print('global_variable =', global_variable)
# updating (incrementing) variables:
x = 0
x = x + 1
print('x =', x)
x += 1 # same as x = x + 1
print('x =', x)
x *= 2 # same as x = x * 2
print('x =', x)
# examples of logical operators:
if x > 0 and x < 10:
print('x is between 0 and 10')
if x < 0 or x > 3:
print('x is less than 0 or greater than 3')
# example of a list of integers:
number_list = [1, 2, 3, 4, 5]
print('number_list =', number_list)
# print first item of number_list:
print('number_list[0] =', number_list[0])
# function to determine length of list:
print('number of items:', len(number_list))
# example of list traversal:
for i in range(len(number_list)):
print(number_list[i])
# examples of list slicing:
print(number_list[0:3]) # first 3 items
print(number_list[:3]) # same as [0:3]
print(number_list[3:]) # slice starting from 3rd item