Experiment 1
Prarambh Nandusekar
SY IT B 43
Aim:Write python programs to implement the Control Flow Statements including Comments,
Data Types, Expressions, Input and Output function.
Source Code:
Comments
# This is a single-line comment in Python
"""
This is a multi-line comment in Python.
It can span multiple lines.
"""
Data Types
# Numeric data types
a = 10 # Integer
b = 10.5 # Float
c = 10 + 5j # Complex number
print("Integer:", a)
print("Float:", b)
print("Complex number:", c)
# Sequence data types
fruits = ["apple", "banana", "cherry"] # List
colors = ("red", "green", "blue") # Tuple
print("List:", fruits)
print("Tuple:", colors)
# Mapping data type
person = {"name": "John", "age": 30} # Dictionary
print("Dictionary:", person)
Expressions
# Arithmetic expressions
a = 10
b=5
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
# Comparison expressions
print("Equal:", a == b)
print("Not equal:", a != b)
print("Greater than:", a > b)
print("Less than:", a < b)
# Logical expressions
print("And:", a > b and a == 10)
print("Or:", a > b or a == 5)
print("Not:", not a > b)
# Input function
name = input("Enter your name: ")
print("Hello,", name)
# Output function (print())
print("Hello, world!")
# Output function with multiple arguments
print("Hello,", "world!")
# Output function with separator
print("Hello", "world", sep="-")
# Output function with end
print("Hello", end=" ")
print("world")
Control Flow Statements
If-Else Statement
a = 10
if a > 5:
print("a is greater than 5")
else:
print("a is less than or equal to 5")
For Loop
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
While Loop
i=0
while i < 5:
print(i)
i += 1
Break and Continue statements
for i in range(5):
if i == 3:
break
print(i)
for i in range(5):
if i == 3:
continue
print(i)
Output screenshots
Comments
Datatypes
Input Output functions
Iterative functions
Screenshots on next pages
Continuous and Break statements
Expressions