R
Rishtaara
Computer Science · Class 8

Data Types and Control Flow

Learn Data Types and Control Flow with notes, examples, and practice questions.

3 sections15–25 min read6 MCQs · 2 examples

Chapter Overview

Data types and control flow (if/else, loops) let programs make decisions and repeat tasks based on conditions.

Data Types

  • int, float, str, bool
  • type() shows data type
  • input() returns string — cast with int()

Control Flow

  • if/elif/else for decisions
  • for loop: iterate sequence
  • while loop: repeat while condition true

Solved Examples

Step-by-step solutions — read each step before checking the final answer.

Trace if-else

age=15. What prints for if age>=18 else Minor?

  1. 115 < 18
  2. 2else branch runs
  3. 3Prints Minor

Answer

Minor

Loop count

How many times does for i in range(3) run?

  1. 1range(3) → 0, 1, 2
  2. 2Three iterations

Answer

3 times

Key Points to Remember

  • Functions can have default parameters
  • Avoid infinite while loops
  • Use elif for multiple conditions

Exam Tips

  • Write function with return
  • Trace loop iterations
  • Know type conversion

Practice MCQs — Data Types and Control Flow

Test your understanding with topic-wise multiple choice questions. Explanations appear after each answer.

Question 1 of 6Score: 0/0

def keyword: