0% found this document useful (0 votes)
58 views23 pages

Python Basics: Input/Output Examples

The document provides a structured introduction to Python programming, starting with the basics of input/output and simple code examples. It outlines a practice plan covering various topics such as operators, conditional statements, loops, functions, and more, along with specific programming exercises for each topic. Additionally, it suggests checking the contents of relevant books from Nirali Prakashan to ensure they align with the user's syllabus.

Uploaded by

Swati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views23 pages

Python Basics: Input/Output Examples

The document provides a structured introduction to Python programming, starting with the basics of input/output and simple code examples. It outlines a practice plan covering various topics such as operators, conditional statements, loops, functions, and more, along with specific programming exercises for each topic. Additionally, it suggests checking the contents of relevant books from Nirali Prakashan to ensure they align with the user's syllabus.

Uploaded by

Swati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Perfect That’s even better — learning by reading and running code is the fastest way to

understand Python.

Let’s start topic by topic with actual code examples


Today we’ll cover Topic 1: Basics & Input/Output — with 6 simple programs you can try right
away.

Topic 1: Basics & Input/Output


Concept Recap

print() used to display output

input() used to take user input

Variables store data

int(), float(), str() type conversions

Example 1: Print your name, age, and city


# Example 1: Print basic info
name = "Swati"
age = 22
city = "Kolhapur"

print("My name is", name)


print("I am", age, "years old.")
print("I live in", city)
Example 2: Take user input and display it
# Example 2: Taking user input
name = input("Enter your name: ")
age = input("Enter your age: ")

print("Hello", name + "!", "You are", age, "years old.")

Example 3: Add two numbers (with type conversion)


# Example 3: Add two numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

sum = num1 + num2


print("The sum is:", sum)

Example 4: Convert temperature (Celsius Fahrenheit)


# Example 4: Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)

Example 5: Find square and cube of a number


# Example 5: Square and Cube
num = int(input("Enter a number: "))
square = num ** 2
cube = num ** 3

print("Square:", square)
print("Cube:", cube)

Example 6: Swap two numbers


# Example 6: Swap two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("Before swapping: a =", a, ", b =", b)

# Swapping
a, b = b, a

print("After swapping: a =", a, ", b =", b)

Would you like me to continue next with Topic 2: Operators (with similar simple code examples
and explanations)?

That’s a great plan, Swati!


Practicing topic-wise examples is the best way to understand Python deeply — especially for BCA
and software development goals.

Let’s build your Python practice roadmap step-by-step.


Below is a list of topics (in order) with example problems for each one — from basic to
intermediate.

PYTHON PRACTICE PLAN (Topic-Wise)


1. Basics & Input/Output

Concepts: print(), input(), comments, variables, data types.


Practice examples:

1.
Print your name, age, and city.

2.
Take user input for two numbers and print their sum.

3.
Convert temperature from Celsius to Fahrenheit.

4.
Find the square and cube of a number.
5.
Swap two numbers using a temporary variable and without using one.

2. Operators

Concepts: Arithmetic, Relational, Logical, Assignment, Bitwise.


Practice examples:

1.
Calculate area and perimeter of a rectangle.

2.
Check whether a number is even or odd.

3.
Compare two numbers using relational operators.

4.
Use logical operators to check if a number is between 10 and 50.

5.
Use shorthand operators (+=, -=, etc.) in a small program.

3. Conditional Statements (if, elif, else)

Concepts: Decision making.


Practice examples:

1.
Check if a number is positive, negative, or zero.

2.
Find the largest among three numbers.
3.
Check if a year is a leap year or not.

4.
Create a simple calculator using if-elif-else.

5.
Check if a character is a vowel or consonant.

4. Loops (for, while)

Concepts: Iteration, range(), nested loops.


Practice examples:

1.
Print numbers from 1 to 10.

2.
Print the multiplication table of any number.

3.
Find the sum of the first N natural numbers.

4.
Display all even numbers between 1 and 100.

5.
Print patterns like:

*
**
***
****
5. Functions

Concepts: Defining, calling, parameters, return values.


Practice examples:

1.
Write a function to find factorial of a number.

2.
Write a function to check if a number is prime.

3.
Write a function to calculate simple interest.

4.
Write a function to find the maximum of three numbers.

5.
Write a recursive function to print Fibonacci series.

6. Lists

Concepts: Indexing, slicing, methods (append, sort, pop, etc.).


Practice examples:

1.
Store 5 numbers in a list and print them.

2.
Find the largest and smallest number in a list.

3.
Count how many times an element appears in a list.

4.
Reverse a list without using reverse() function.
5.
Sort a list in ascending and descending order.

7. Tuples and Sets

Practice examples:

1.
Create a tuple and access elements using index.

2.
Convert list to tuple and vice versa.

3.
Create a set and perform union, intersection.

4.
Remove duplicates from a list using a set.

5.
Check if two sets are disjoint.

8. Dictionaries

Concepts: Key-value pairs.


Practice examples:

1.
Create a dictionary with student names and marks.

2.
Add, update, and delete dictionary entries.
3.
Print all keys and values separately.

4.
Check if a key exists in a dictionary.

5.
Find the student with highest marks.

9. Strings

Concepts: Indexing, slicing, methods (upper(), replace(), etc.).


Practice examples:

1.
Count vowels in a string.

2.
Check if a string is palindrome.

3.
Reverse a string.

4.
Count words in a sentence.

5.
Replace all spaces with hyphens.

10. File Handling

Concepts: open(), read/write modes.


Practice examples:
1.
Write user input into a file.

2.
Read the contents of a text file.

3.
Count the number of lines in a file.

4.
Append new data to an existing file.

5.
Copy the content of one file to another.

11. Exception Handling

Practice examples:

1.
Handle divide-by-zero error.

2.
Handle invalid input using try-except.

3.
Raise your own exception for invalid marks.

4.
Use finally block to print a message always.

12. Object-Oriented Programming (OOPs)


Concepts: Class, Object, Constructor, Inheritance, Polymorphism.
Practice examples:

1.
Create a class Student with name and marks as attributes.

2.
Create a class Rectangle to calculate area and perimeter.

3.
Demonstrate inheritance using Animal Dog.

4.
Demonstrate method overriding.

5.
Create a class with __init__() and __str__() methods.

Would you like me to start giving you small daily practice sets (5 questions per day) topic-wise —
starting from “Basics & Input/Output”?
That way, you can learn step-by-step with explanations and solutions.

Perfect That’s even better — learning by reading and running code is the fastest way to
understand Python.

Let’s start topic by topic with actual code examples


Today we’ll cover Topic 1: Basics & Input/Output — with 6 simple programs you can try right
away.

Topic 1: Basics & Input/Output


Concept Recap

print() used to display output


input() used to take user input

Variables store data

int(), float(), str() type conversions

Example 1: Print your name, age, and city


# Example 1: Print basic info
name = "Swati"
age = 22
city = "Kolhapur"

print("My name is", name)


print("I am", age, "years old.")
print("I live in", city)

Example 2: Take user input and display it


# Example 2: Taking user input
name = input("Enter your name: ")
age = input("Enter your age: ")

print("Hello", name + "!", "You are", age, "years old.")

Example 3: Add two numbers (with type conversion)


# Example 3: Add two numbers
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

sum = num1 + num2


print("The sum is:", sum)
Example 4: Convert temperature (Celsius Fahrenheit)
# Example 4: Celsius to Fahrenheit
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit:", fahrenheit)

Example 5: Find square and cube of a number


# Example 5: Square and Cube
num = int(input("Enter a number: "))
square = num ** 2
cube = num ** 3

print("Square:", square)
print("Cube:", cube)

Example 6: Swap two numbers


# Example 6: Swap two numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print("Before swapping: a =", a, ", b =", b)

# Swapping
a, b = b, a

print("After swapping: a =", a, ", b =", b)

Would you like me to continue next with Topic 2: Operators (with similar simple code examples
and explanations)?

Awesome, Swati!
Let’s move on to Topic 2: Operators in Python — with clear explanations and working code
examples.
These will help you understand how arithmetic, comparison, logical, and assignment operators
work.
Topic 2: Operators
Concept Recap

Python has several types of operators:

1.
Arithmetic operators +, -, *, /, %, **, //

2.
Comparison (Relational) operators ==, !=, <, >, <=, >=

3.
Logical operators and, or, not

4.
Assignment operators =, +=, -=, etc.

Example 1: Arithmetic Operators


# Example 1: Arithmetic operators
a = 10
b=3

print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Floor Division:", a // b)
print("Modulus (Remainder):", a % b)
print("Exponent (Power):", a ** b)

Output:

Addition: 13
Subtraction: 7
Multiplication: 30
Division: 3.3333
Floor Division: 3
Modulus: 1
Exponent: 1000

Example 2: Area and Perimeter of a Rectangle


# Example 2: Area and Perimeter
length = float(input("Enter length: "))
width = float(input("Enter width: "))

area = length * width


perimeter = 2 * (length + width)

print("Area:", area)
print("Perimeter:", perimeter)

Example 3: Comparison Operators


# Example 3: Comparison operators
x = 15
y = 10

print("x == y:", x == y)
print("x != y:", x != y)
print("x > y:", x > y)
print("x < y:", x < y)
print("x >= y:", x >= y)
print("x <= y:", x <= y)

This checks how two values relate (equal, greater, etc.)

Example 4: Logical Operators


# Example 4: Logical operators
num = int(input("Enter a number: "))

# Check if number is between 10 and 50


if num >= 10 and num <= 50:
print("The number is between 10 and 50.")
else:
print("The number is out of range.")
# Check if number is NOT negative
if not (num < 0):
print("The number is non-negative.")

Example 5: Assignment Operators


# Example 5: Assignment operators
x = 10
print("Initial value of x:", x)

x += 5 # same as x = x + 5
x -= 2 # same as x = x - 2
x *= 3 # same as x = x * 3
x //= 2 # same as x = x // 2

print("Final value of x:", x)

Example 6: Even or Odd Check


# Example 6: Even or Odd
num = int(input("Enter a number: "))

if num % 2 == 0:
print(num, "is Even.")
else:
print(num, "is Odd.")

Would you like me to continue next with Topic 3: Conditional Statements (if, elif, else) — with real
code examples like leap year check, calculator, etc.?

I searched for a book from Nirali Prakashan that exactly matches your syllabus and here’s what I
found — plus some next-steps to check if it’s the right fit.

What I found
There is a book titled “Information and Cyber Security” (ISBN: 978-9351647096) published by
Nirali Prakashan. (Amazon)

There is another book “Cyber Security” (ISBN: 978-93-5451-322-0) by Nirali Prakashan,


intended for TY BBA (CA) Semester V and focusing on cybercrime, cyber security, tools,
methods, forensics, etc. (Scribd)

However, none of the listings clearly show that the book covers all the modules you listed
(security architecture, network mapping, cryptography, audit, risk management, etc.) in
exactly the sequence you have.

What you should check (to ensure match)

Before you buy, check these details:

1.
Contents/Syllabus match – Look inside the book or preview the table of contents. Does it
include:

Basic security concepts (confidentiality, integrity)

Network layer / transport layer attacks & defenses

Application layer, vulnerabilities, malware, propagation

Cryptographic tools (symmetric, asymmetric, digital signatures, key management)

Security auditing, legal & ethical aspects, risk management

2.
Edition & publisher details – Make sure it’s from Nirali Prakashan and is the latest edition (so
that it has current content).

3.
For your course & semester – Some Nirali books may be for other specific streams or
semesters (e.g., TY BBA CA, TE IT). Make sure it aligns with your course: BCA 3rd semester or
whatever your subject code is.

4.
Supplementary coverage – If your syllabus is wide (as yours is), you may find that one book
covers most topics, but you might need another short book or online notes for the remainder.

If you like, I can scan for all books by Nirali Prakashan that cover exactly your full syllabus (with
chapter-by-chapter match) and send you 2-3 best options, along with direct purchase links
(India). Would you like me to do that?

Great — here are 2 strong book options from Nirali Prakashan that might match your syllabus,
plus how to check if they fit perfectly.

Advance Network Security (SY BSc Cyber Security) Nirali


Prakashan

direct Nirali publication

₹170

Information Security Semester 6Nirali Prakashan

semester specific Nirali

₹304

INFORMATION SECURITY Nirali Prakashan

general Nirali info‑sec


₹788

Information Security 3Ed An Indian Adaptation

international adaptation

₹569

Information Security (generic)

generic info‑sec book

₹356

Information Security: Principles And Practices

fundamental principles book

₹678

Summary of Each Option

Advance Network Security (SY BSc Cyber Security) Nirali Prakashan: Specifically for “SY BSc
Cyber Security Semester 3” according to the listing — may cover many topics but perhaps not
exactly your semester/subject.

Information Security Semester 6Nirali Prakashan: Tailored for Semester 6 course — might
align with your later part of syllabus (cryptography, audits, etc).

INFORMATION SECURITY Nirali Prakashan: A more generic title from Nirali; may have broader
coverage.

Information Security 3Ed An Indian Adaptation: Not a Nirali book specifically (might be
different publisher) — useful if you cannot find exact Nirali match.
Information Security (generic): Generic title — for reference if Nirali one doesn’t match.

Information Security: Principles And Practices: A principles book; good backup if syllabus
strongly theoretical.

My Recommendation

From these, your best bets are the first two (Nirali-specific). Pick the one whose table of contents
(TOC) most closely matches your syllabus modules (basic security attacks protocols
malware cryptography auditing laws & risk).

How to Verify Fit

Before buying, check:

The Table of Contents: Does it list chapters like “Network mapping”, “TCP/UDP scanning”,
“Transport layer attacks”, “Application layer attacks”, “Malicious software types”,
“Cryptographic tools (sub-modules)”, “Security auditing”, “Legal & ethical aspects”, “Risk
management”?

The Edition and Year: A recent edition will likely cover current topics (DDoS, forensics, cloud
security etc).

The Semester/course code: Make sure it is for your course (BCA 3rd semester or whichever
your subject is) and not for a different stream.

The Publisher: Must be Nirali Prakashan, so you get local Indian syllabus coverage.

Purchase Tips

Visit Nirali’s official catalogue via their website. ([Link])


Use the exact ISBN listed on the book’s page to avoid buying a mismatched version.

If possible, preview the first few pages / TOC in a physical bookstore or online preview.

If you like, I can check 5 more Nirali titles (with full TOC details) and find which one best matches
all 18 lectures and modules you shared. Would you like me to do that?

Great — here are 5 book options from Nirali Prakashan along with what I found about their Table
of Contents (TOC) / suitability. You can compare these with your syllabus and pick the best. I’ll
mark how closely each matches your full 18-lecture outline.

Information Security (Nirali Prakashan)

likely match full syllabus

₹356

Information Security Semester 6 (Nirali


Prakashan)

semester‑specific match

₹304

Advance Network Security for SY BSc (Cyber


Security) Sem 3 (Nirali
Prakashan)

network security narrower

₹170

INFORMATION SECURITY (NiraliPrakashan – Generic)


generic title

₹788

Information Security 3rd Ed An Indian Adaptation

international adaptation

₹569

Book Details & Match Evaluation

Information Security (Nirali Prakashan):


This appears to be a book by Nirali on Information Security. From the preview/TOC snippets
(see search result turn0search4) it lists key topics: symmetric key cryptography, asymmetric,
web security, network & system security, etc. ([Link])
Match: Good; covers many crypto, network & system security topics. Might require checking
whether it covers “attack vectors & scanning” and “transport/application layer attacks” in
same depth.

Information Security Semester 6 (Nirali Prakashan):


This is explicitly semester-specific (Semester 6). Could be good if your subject falls in that
semester.
Match: Reasonable, but you must verify if it includes the early lectures on basic security,
network mapping, ICMP/TCP scanning etc. Might be oriented more on cryptography and
higher modules.

Advance Network Security for SY BSc (Cyber Security) Sem 3 (Nirali Prakashan):
This is more specialized in network security and explicitly for “SY BSc Cyber Security
Semester 3”.
Match: Narrower than your full syllabus. Good if you needed just the attack/defense protocols
modules, but likely misses cryptography + auditing + risk management.

INFORMATION SECURITY (NiraliPrakashan – Generic):


This seems a generic title (maybe broader/higher level) from Nirali.
Match: Possibly covers major topics but may not be tailored specifically to your 18-lecture
structured syllabus. Need TOC check.
Information Security 3rd Ed An Indian Adaptation :
This appears to be from a different publisher maybe (international adaptation) but included
for completeness.
Match: Might have very good depth but may not align exactly to Indian syllabus or Nirali’s
local edition.

What to check (TOC) for each book

For each you consider, verify:

Does it start with basic security (confidentiality, integrity, security architecture)

Does it cover network mapping/ICMP, TCP/UDP port scanning, DoS/DDoS (lectures 2/3)

Does it cover network layer, transport layer, application layer attacks & defenses (lectures 4-6)

Does it cover malicious software types, propagation, social engineering (lectures 7-8)

Does it cover cryptographic tools sub-modules 1-5 (lectures 9-12)

Does it cover auditing, legal/ethical aspects, cyber crime, risk management (lectures 13-18)

Includes case‐studies, industry assignment support

My Suggestion

If I were you: check Information Security (Nirali Prakashan) first (Book 1 above). If its TOC covers
all the above lecture-modules, that’s the one.
If not, you may choose Information Security Semester 6 for the latter part, and supplement with
another book for the earlier modules.
If you like, I can find full TOC scans (images/pages) for each of the 5 books (or as many as
available) and send you PDF links so you can review side-by-side with your syllabus. Would that
be okay?

You might also like