Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Practice › Class 12 › Computer Science

Python functions and files: practice questions

Class 12 Computer Science. Ten questions with step-by-step answers, for CBSE and ICSE. Try each one before you open its answer.

Practise this with your AI tutorGo to the questions

Key ideas

  • Scope, arguments and file handling.
  • These are the multi-step questions examiners like to set. Read each one twice, write down what you know, then plan before you calculate.
  • These go beyond the syllabus. Each one has a neat idea that makes it short; brute force is slow.

Read each question twice and say the answer out loud before you check it. For code or binary questions, work it out on paper step by step, the way a computer would.

Ten questions

  1. 1.def f(x): return 4 * x + 9 print(f(8))

    Show the answer

    Think: What does return give back?

    Work: Put the argument in for x.

    Answer: 41

  2. 2.What does this print? x = 3 y = 7 print(x * y + 1)

    Show the answer

    Think: // is whole-number division, % is the remainder.

    Work: Run it line by line.

    Answer: 22

  3. 3.def f(x): return 8 * x + 4 print(f(5))

    Show the answer

    Think: What does return give back?

    Work: Put the argument in for x.

    Answer: 44

  4. 4.What does this print? print(24 // 4)

    Show the answer

    Think: // is whole-number division, % is the remainder.

    Work: Run it line by line.

    Answer: 6

  5. 5.def f(x): return 2 * x + 3 print(f(8))

    Show the answer

    Think: What does return give back?

    Work: Put the argument in for x.

    Answer: 19

  6. 6.What does this print? x = 4 y = 9 print(x * y + 1)

    Show the answer

    Think: // is whole-number division, % is the remainder.

    Work: Run it line by line.

    Answer: 37

  7. 7.def f(x): return 4 * x + 9 print(f(4))

    Show the answer

    Think: What does return give back?

    Work: Put the argument in for x.

    Answer: 25

  8. 8.What does this print? print(31 % 5)

    Show the answer

    Think: // is whole-number division, % is the remainder.

    Work: Run it line by line.

    Answer: 1

  9. 9.def f(x): return 2 * x + 1 print(f(2))

    Show the answer

    Think: What does return give back?

    Work: Put the argument in for x.

    Answer: 5

  10. 10.What does this print? x = 6 y = 6 print(x * y + 1)

    Show the answer

    Think: // is whole-number division, % is the remainder.

    Work: Run it line by line.

    Answer: 37

Before you check an answer

  • What does return give back?
  • // is whole-number division, % is the remainder.

Questions students ask

What does Python functions and files in Class 12 Computer Science cover?
Scope, arguments and file handling. These are the multi-step questions examiners like to set. Read each one twice, write down what you know, then plan before you calculate. These go beyond the syllabus. Each one has a neat idea that makes it short; brute force is slow.
How should I practise Python functions and files?
Read each question twice and say the answer out loud before you check it. For code or binary questions, work it out on paper step by step, the way a computer would. Try all ten questions on this page, then open the chapter in Gradient tuition for step-by-step lessons, a live experiment and an AI tutor who explains where you went wrong.
Is this for CBSE or ICSE?
The questions follow the Class 12 Computer Science syllabus shared by CBSE and ICSE / ISC, and suit most state boards too.

Stuck on one of these?

Gradient tuition teaches Python functions and files step by step, with experiments you can play with and an AI tutor who circles the part of the question you missed.

Open Python functions and files in tuition
Data structures: stacks