PART 1 โ€ข LEVEL 02

๐Ÿ“ฆ Data Types & I/O

Learn how Python stores values, identifies their types, accepts keyboard input, converts data and produces clear formatted output.

โฑ 75โ€“90 minutes๐Ÿ“š 8 concepts๐Ÿ’ป 5 programs๐Ÿง  6-question quiz
student_profile.pyPython 3
name = input("Name: ")
age = int(input("Age: "))
next_age = age + 1

print(f"Hello, {name}!")
print(f"Next year: {next_age}")
OUTPUTHello, Venu!
Next year: 21

By the End of This Level

You will be able to store, inspect, receive, convert and display data correctly.

01

Create variables using meaningful names and assignment.

02

Distinguish numeric, text, Boolean and empty values.

03

Use input() and convert text into required data types.

04

Produce readable output with commas and f-strings.

01

Variables and Assignment

A variable is a meaningful name that refers to a value. Python creates the variable when an assignment statement runs.

In student_name = "Venu", the assignment operator = evaluates the value on the right and associates it with the name on the left.

Remember

= assigns a value; it does not mean โ€œis mathematically equal to.โ€

EXAMPLE 1

Create and Update Variables

course = "Python"
lessons = 12
progress = 2

progress = progress + 1

print(course)
print("Completed:", progress)
OUTPUT
Python
Completed: 3
1

Start Correctly

name
student_name
marks2

Begin with a letter or underscore; digits may appear later.

2

Use Valid Characters

total_marks
course1
_count

Use letters, digits and underscoresโ€”never spaces or hyphens.

3

Avoid Keywords

# Invalid names
class = 10
if = True

Reserved Python keywords cannot be variable names.

4

Choose Meaningful Names

student_age = 20
total_price = 499.0

Clear names explain the value without needing extra comments.

02

Python Numeric Data Types

Python provides different numeric types because whole numbers, decimal values and complex values represent different kinds of information.

๐Ÿ”ข

int

Whole numbers without a decimal point, such as 25, -7 and 0.

๐Ÿ“

float

Numbers with a decimal point, such as 72.5 and -0.25.

๐Ÿงฎ

complex

Numbers containing real and imaginary parts, such as 3 + 2j.

โœ…

bool

Logical values True and False; Boolean is related to integers.

ValueTypeTypical use
42intCount, age, score
85.75floatAverage, price, measurement
2 + 3jcomplexScientific and engineering calculations
TrueboolConditions and yes/no states
03

Strings, Boolean Values and None

LOGICAL STATE

๐Ÿšฆ Boolean โ€” bool

A Boolean records whether something is true or false.

is_registered = True
is_completed = False
NO VALUE YET

โญ• None โ€” NoneType

None represents the intentional absence of a value.

result = None
selected_course = None
Important

"25" is a string because it is inside quotes, while 25 is an integer. Their appearance is similar, but their behavior is different.

04

Check a Value with type()

The built-in type() function reports the data type of a value or variable.

EXAMPLE 2

Inspect Several Values

age = 20
average = 87.5
name = "Venu"
is_ready = True

print(type(age))
print(type(average))
print(type(name))
print(type(is_ready))
OUTPUT
<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>
05

Keyboard Input with input()

input() displays an optional prompt, waits for the user, and always returns the entered data as a string.

1Show Promptinput("Age: ")
โ†’
2User Types20
โ†’
3String Returned"20"
EXAMPLE 3

Receive and Display a Name

name = input("Enter your name: ")
city = input("Enter your city: ")

print("Student:", name)
print("City:", city)
SAMPLE OUTPUT
Enter your name: Venu
Enter your city: Hyderabad
Student: Venu
City: Hyderabad
Critical rule

Even when the user types digits, input() returns text. Convert the value before performing numeric calculations.

06

Type Conversion

Type conversion creates a value of another compatible type. Common conversion functions are int(), float(), str() and bool().

FunctionPurposeExampleResult
int()Convert to integerint("25")25
float()Convert to decimal numberfloat("7.5")7.5
str()Convert to textstr(100)"100"
bool()Convert to logical valuebool(1)True
EXAMPLE 4

Calculate Using Converted Input

length = float(input("Length: "))
width = float(input("Width: "))

area = length * width

print("Area =", area)
SAMPLE OUTPUT
Length: 8
Width: 5
Area = 40.0
โœ“ VALID
age = int("20")
price = float("49.5")

The text contains a compatible numeric value.

โœ• VALUEERROR
age = int("twenty")
count = int("4.5")

The text cannot be directly represented as an integer.

07

Formatted Output

Use commas for simple labelled output and f-strings when values must appear naturally inside a message.

COMMA-SEPARATED
name = "Venu"
score = 92
print("Student:", name)
print("Score:", score)

print() automatically places a space between comma-separated values.

F-STRING
name = "Venu"
score = 92
print(f"{name} scored {score}")

Prefix the string with f and place expressions inside braces.

EXAMPLE 5

Student Result Card

name = input("Name: ")
marks = float(input("Marks: "))

print(f"Student: {name}")
print(f"Marks: {marks}")
print(f"Passed: {marks >= 40}")
SAMPLE OUTPUT
Name: Venu
Marks: 78.5
Student: Venu
Marks: 78.5
Passed: True

Common Data and Input Mistakes

TypeError
"Age: " + 20

A string and integer cannot be joined with + without conversion.

ValueError
int("twenty")

The text does not contain a valid integer representation.

Wrong result
age = input()
print(age + "1")

Entering 20 produces 201 because both values are strings.

Before calculating:1. Read input2. Identify required type3. Convert4. Calculate5. Display
QUICK REVISION

๐Ÿ“Œ Data Types & I/O โ€” Quick Revision

Review the complete Level 2 lesson before attempting the quiz and programming problems.

01

A variable is created when a value is assigned using =.

02

int stores whole numbers and float stores decimal numbers.

03

str stores text inside matching quotes.

04

bool has the values True and False.

05

None represents the intentional absence of a value.

06

type() reports the data type of a value.

07

input() always returns a string.

08

Use int() or float() before numeric calculations.

09

f-strings insert values using braces such as f"Age: {age}".

10

A failed incompatible conversion normally raises a ValueError.

Level 2 Quick Quiz

Select one answer for every question, then check your score.

6 Questions
1What type is the value 25.0?
2What does input() return?
3Which statement correctly reads an integer age?
4What is the output type of str(100)?
5Which is a valid variable name?
6What does f"Total: {price}" represent?

PRACTICE

๐ŸŽฏ 5 Programming Problems โ€” Data Types & I/O

Solve every problem in the browser workspace. The runner uses the displayed sample input, so you can practise input(), conversion, variables, calculations and output.

๐Ÿ“ˆ Data Types & I/O Practice Progress
Solved0 / 5
Completed with Solution0
Total Score0 / 500
Completion0%

A problem counts as Solved when its output passes before the official solution is opened.

1. Personal Greeting

Read a name and display the exact two-line welcome message.

Sample input: VenuExpected output: Hello, Venu! and Welcome to CodeBhavya.
2. Age Next Year

Read the current age as an integer and display the age next year.

Sample input: 20Expected output: Next age = 21
3. Rectangle Area

Read integer length and width, calculate the area and display it.

Sample input: 8, 5Expected output: Area = 40
4. Shopping Bill

Read a decimal price and integer quantity, then display the total amount.

Sample input: 249.5, 2Expected output: Total = 499
5. Celsius to Fahrenheit

Read Celsius temperature, convert it and display the Fahrenheit value.

Sample input: 25Expected output: Fahrenheit = 77
KEY TAKEAWAY

๐ŸŽฏ Give Every Value the Right Journey

1Read

Receive raw text using input().

โ†’
2Convert

Choose int, float or another suitable type.

โ†’
3Process

Calculate using clearly named variables.

โ†’
4Present

Display a labelled result with print() or an f-string.

Correct programs depend on correct data representation. Before every operation, ask: โ€œWhat value do I have, and what type does this operation require?โ€

INTERACTIVE LEARNING

๐ŸŽฌ Input, Conversion and Output โ€” Visual Flow

Follow user data from the keyboard until Python displays the calculated result.

PROGRAM TRACING

๐Ÿ”Ž Program Tracing โ€” Student Input

Move through the program one statement at a time and observe input consumption, variable types, calculations and output.

INTERVIEW PREPARATION

๐ŸŽค Data Types & I/O โ€” Interview Questions

Answer aloud before opening each explanation.

1.

What is dynamic typing in Python?

2.

What is the difference between int and float?

3.

Why must numeric keyboard input often be converted?

4.

What is the difference between implicit and explicit conversion?

5.

What does None represent?

6.

Why are f-strings useful?

EXTRA TIPS

๐Ÿ’ก Data Types & I/O โ€” Extra Tips

  • 01

    Name variables according to meaning: prefer total_marks over x.

  • 02

    Use type() while learning or debugging unexpected data behavior.

  • 03

    Convert input immediately when the rest of the program expects a number.

  • 04

    Use float() when valid input may contain a decimal point.

  • 05

    Keep input, processing and output as three clear stages in beginner programs.

  • 06

    Test conversions with normal, boundary and invalid values to understand failures.

EXTRA PRACTICE

โœ๏ธ Data Types & I/O โ€” Extra Practice Questions

  1. Create variables for a student's name, roll number, percentage and pass status; display their types.
  2. Read two integers and display their sum, difference and product.
  3. Read length and breadth as decimal values and display a rectangle's area and perimeter.
  4. Read a name and department, then create a two-line profile using f-strings.
  5. Convert the string "125" to an integer and add 25.
  6. Predict the results of type("10"), type(10) and type(10.0).
  7. Explain why input() + input() may join digits instead of adding numbers.
  8. Correct the error in total = "Price: " + 499 using two different approaches.
  9. Read minutes and convert them into hours and remaining minutes.
  10. Build a bill program that reads item name, price and quantity and prints a formatted summary.

Data Types & I/O Complete

When you can choose suitable types, convert input correctly and solve the five programs without help, mark this level complete and continue.