Tag: LENGTH

National 5 – SDD Predefined Functions

So today we were looking over predefined function. For the N5 course we have to be aware of RANDOM, ROUND, & LENGTH.

The RANDOM function picks an integer between two values.

import random
number=random.randint(1,20) # random(StartValue,EndValue)
print(number)

The ROUND function rounds a real number (floating point) to a fixed number of decimal points.

a=1.2 # 1
b=2.6 # 3
c=2.5 # 2
d=3.5 # 4
e=3.453444354

print(round(e,2)) # round(valueToRound,NoOfDecimalDigits)

The LENGTH function displays the number of characters in a String or the length of an Array.

name="Stratton was here"
numbers=[1,2,3,4,2,3,4,6,4,3,2,43]
print(len(name))
print(len(numbers))
print(numbers)

for index in range(len(numbers)):
    print(numbers[index])

for index in range(len(name)):
    print(name[index])