Python Ex
Python Ex
Name of Student: _________________ Class : B.Tech (CSE) IV Sem (C) Batch : __ Roll No.: 0905CS22____
# Floating point
num_float = 10.5
print("Float: ", num_float)
# Complex number
num_complex = 3 + 4j
print("Complex: ", num_complex)
# Boolean
num_bool = True
print("Boolean: ", num_bool)
Output.
Integer: 10
Float: 10.5
Complex: (3+4j)
Boolean: True
=== Code Execution Successful ===
Experiment No. 2
Write a program to perform different Arithmetic Operations on
numbers in Python.
Input.
# Define the numbers
num1 = 10
num2 = 5
# Addition
print("Addition: ", num1 + num2)
# Subtraction
print("Subtraction: ", num1 - num2)
# Multiplication
print("Multiplication: ", num1 * num2)
# Division
print("Division: ", num1 / num2)
# Modulus
print("Modulus: ", num1 % num2)
# Exponentiation
print("Exponentiation: ", num1 ** num2)
# Floor division
print("Floor division: ", num1 // num2)
Output.
Addition: 15
Subtraction: 5
Multiplication: 50
Division: 2.0
Modulus: 0
Exponentiation: 100000
Floor division: 2
# Concatenate strings
str3 = str1 + " " + str2
print("Concatenated String: ", str3)
# Access substring
substr = str3[0:5]
print("Substring: ", substr)
Output.
# Append an element
list1.append(4)
print("List After Appending: ", list1)
# Remove an element
list1.remove(2)
print("List After Removing: ", list1)
Output.
Original List: [1, 2, 3]
List After Appending: [1, 2, 3, 4]
List After Removing: [1, 3, 4]
# Create a tuple
tuple1 = (1, 2, 3)
print("Original Tuple: ", tuple1)
# Length of a tuple
print("Length of Tuple: ", len(tuple1))
# Concatenation of tuples
tuple2 = (4, 5, 6)
tuple3 = tuple1 + tuple2
print("Concatenated Tuple: ", tuple3)
# Repetition in tuple
tuple4 = tuple1 * 3
print("Repeated Tuple: ", tuple4)
Output.
Input.
# Create a dictionary
dict1 = {'name': 'John', 'age': 25, 'job': 'Engineer'}
print("Original Dictionary: ", dict1)
Output.
Output.
Input.
Output.
Input.
# Number of rows
rows = 5
Output.
*
**
***
****
*****
=== Code Execution Successful ===
Experiment No. 10
Write a Python script that prints prime numbers less
than 20.
Input.
Output.
2
3
5
7
11
13
17
19
Input.
Output.
Input.
import numpy as np
Output.
Input.
import numpy as np
Output.