0% found this document useful (0 votes)
86 views

Big Data Assignment - 1

This document contains Python code examples demonstrating various Python concepts like strings, variables, data types, input/output, conditional statements, loops, functions, and classes. The code samples show how to get the length of a string, slice a substring, define variables of different types, use input to get user input, calculate the area of a circle, iterate with for loops, use if/elif conditional logic, define and call functions, and create a Cube class with methods to calculate perimeter, area and volume.

Uploaded by

Rajeev Mukhesh
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)
86 views

Big Data Assignment - 1

This document contains Python code examples demonstrating various Python concepts like strings, variables, data types, input/output, conditional statements, loops, functions, and classes. The code samples show how to get the length of a string, slice a substring, define variables of different types, use input to get user input, calculate the area of a circle, iterate with for loops, use if/elif conditional logic, define and call functions, and create a Cube class with methods to calculate perimeter, area and volume.

Uploaded by

Rajeev Mukhesh
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
You are on page 1/ 3

In 

[1]:
var = "Hello, World!"

print(len(var))

13

In [2]:
print(var[7:12])

World

In [3]:
a, b, c = 1, 1.0, '1'

print(type(a))

print(type(b))

print(type(c))

<class 'int'>

<class 'float'>

<class 'str'>

In [17]:
pi = 3.14

r = float(input("Enter the radius of the circle: "))

area = pi * r * r

print("Area of the circle: %0.2f" %area)

#print(round(area,2))

Enter the radius of the circle: 5

Area of the circle: 78.50

In [18]:
for x in range(10):

print(x)

In [22]:
for x in range(9, 22):

if(x % 2 == 1):

print(x)

11

13

15

17

19

21

In [33]:
var = int(input("Enter a number: "))

if var == 10:

print("Equal to 10")

elif var < 9:

print("Less than 9")

elif var > 8:

print("Greater than 8")

Enter a number: 9

Greater than 8

In [35]:
var = int(input("Enter a number: "))

if var == 10:

print("Equal to 10")

elif var < 9:

print("Less than 9")

elif var > 8:

print("Greater than 8")

Enter a number: 4

Less than 9

In [36]:
var = int(input("Enter a number: "))

if var == 10:

print("Equal to 10")

elif var < 9:

print("Less than 9")

elif var > 8:

print("Greater than 8")

Enter a number: 10

Equal to 10

In [66]:
def stringLength(intArray):

return len(''.join(map(str, intArray)))

arr = list(map(int, input("Enter the numbers separated by space: ").split(' ')))

print(stringLength(arr))

Enter the numbers separated by space: 23 48 96 159 852 4 3

14

In [79]:
def oddsInRange(n):

if n>0:

for i in range(n):

if(i % 2 == 1):

print(i)

else:

print("Enter positive integer")

num = int(input("Enter the number: "))

oddsInRange(num)

Enter the number: 15

11

13

In [93]:
class Cube:

def __init__(self, side):

self.side = side

def getPerimeter(self):

print("Perimeter of the cube of side {} is ".format(self.side), 12*self.side


def getArea(self):

print("Area of the cube of the side {} is ".format(self.side), 6*self.side**


def getVolume(self):

print("Volume of the cube of the side {} is".format(self.side), self.side**3


n = int(input("Enter side of the cube: "))

c = Cube(n)

c.getPerimeter()

c.getArea()

c.getVolume()

Enter side of the cube: 5

Perimeter of the cube of side 5 is 60

Area of the cube of the side 5 is 150

Volume of the cube of the side 5 is 125

In [ ]:

You might also like