Photo AI
Question 4
A programmer declares the following variables. first = "Computer Science" second = "is great" (a) State one difference between a variable and a constant. (b) Stat... show full transcript
Step 1
Step 2
Answer
The output of the code provided will be as follows:
(i) print(first.length)
will output 15
, as 'Computer Science' contains 15 characters.
(ii) print(second.length DIV 3)
will output 2
, since 'is great' has 8 characters and dividing 8 by 3 gives 2 when considering integer division.
(iii) print(3 ^ 2)
will output 9
, as this is a calculation of 3 raised to the power of 2.
Step 3
Answer
(i) great
can be obtained with:
print(second)
(ii) Computer
can be obtained with:
print(first.substring(0, 8))
(iii) Science is great
can be obtained with:
print(first.substring(9) + " " + second)
This uses substring to extract 'Science' from first
and concatenate it with second
.
Report Improved Results
Recommend to friends
Students Supported
Questions answered
CPU Architecture, Performance & Embedded Systems
Computer Science - AQA
Primary & Secondary Storage
Computer Science - AQA
Data Storage & Compression
Computer Science - AQA
Networks & Topologies
Computer Science - AQA
Wired & Wireless Networks, Protocols & Layers
Computer Science - AQA
Identifying & Preventing Threats to Computer Systems & Networks
Computer Science - AQA
Operating Systems & Utility Software
Computer Science - AQA
Ethical, Legal, Cultural & Environmental Impact
Computer Science - AQA
Computational Thinking, Searching & Sorting Algorithms
Computer Science - AQA
Designing, Creating & Refining Algorithms
Computer Science - AQA
Programming Fundamentals & Data Types
Computer Science - AQA
Additional Programming Techniques
Computer Science - AQA
Defensive Design & Testing
Computer Science - AQA
Boolean Logic Diagrams
Computer Science - AQA
Programming Languages & Integrated Development Environments (IDEs)
Computer Science - AQA
OCR Exam Reference Language
Computer Science - AQA