3
3
Python is a popular and versatile programming language that has gained widespread
adoption in various domains. Let’s explore some key aspects of Python:
1. What is Python?
o Python was created by Guido van Rossum and released in 1991.
o It is used for:
Web development (server-side)
Software development
Mathematics
System scripting
2. What Can Python Do?
o Python can be used to:
Create web applications on servers.
Build workflows alongside software.
Connect to database systems.
Read and modify files.
Handle big data and perform complex mathematics.
Rapidly prototype or develop production-ready software.
3. Why Python?
o Python has several advantages:
Platform Independence: It works on different platforms (Windows,
Mac, Linux, Raspberry Pi, etc.).
Readable Syntax: Python’s syntax is simple and similar to the English
language.
Concise Code: Developers can write programs with fewer lines
compared to other languages.
Interpreted Execution: Code can be executed as soon as it’s written,
allowing quick prototyping.
Versatility: Python supports procedural, object-oriented, and
functional programming styles.
4. Python Versions:
o The most recent major version is Python 3, which we’ll use in this tutorial.
o Python 2, although not actively updated, is still in use for legacy systems.
5. Syntax Comparison:
o Python emphasizes readability:
New lines complete commands (no semicolons or parentheses).
Indentation defines scope (loops, functions, classes).
No curly braces for scoping (unlike other languages).
6. Example:
print("Hello, World!")
1
2. Introduction to python Data Types
___________________________________________________________________________
3. Program to accept two numbers and swap them with each other
x, y = y, x
2
print("x =", x)
print("y =", y)
3
prime_flag = 0
if num > 1:
for i in range(2, int(sqrt(num)) + 1):
if (num % i) == 0:
prime_flag = 1
break
if prime_flag == 0:
print("True")
else:
print("False")
7. Program to calculate and print the sums of even and odd integers
of the first n natural numbers
4
print("#", end="")
print()
if cleaned_input == cleaned_input[::-1]:
print(f"{user_input} is a palindrome!")
else:
print(f"{user_input} is not a palindrome.")
10. Program to check if the highest element of the list lies in the first half of the list or in
second half
def find_max_halves(arr):
n = len(arr)
mid = n // 2
max_first = max(arr[:mid])
if n % 2 == 1:
max_first = max(max_first, arr[mid])
max_second = max(arr[mid:])
5
11. Program to accept a tuple of ten integers. After accepting whole tuple replace the
value of 3rd element with 101
for _ in range(n):
student_name = input("Enter student name: ")
wins = int(input(f"Enter the number of wins for
{student_name}: "))
winners[student_name] = wins
return winners
competition_winners = create_winner_dictionary()
print("Competition Winners:")
for student, wins in competition_winners.items():
6
print(f"{student}: {wins} wins")