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

Python For Beginner_PG_Day2.ipynb - Colab

The document explains data types in programming, including strings, integers, floats, and booleans, along with examples of each. It also covers type casting, demonstrating how to convert between data types and providing examples of calculations using user input. Additionally, it includes a simple code snippet for calculating the area of a rectangle and creating a shopping cart application.

Uploaded by

arbin.rahin
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)
4 views

Python For Beginner_PG_Day2.ipynb - Colab

The document explains data types in programming, including strings, integers, floats, and booleans, along with examples of each. It also covers type casting, demonstrating how to convert between data types and providing examples of calculations using user input. Additionally, it includes a simple code snippet for calculating the area of a rectangle and creating a shopping cart application.

Uploaded by

arbin.rahin
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/ 2

keyboard_arrow_down Data Types

data types are used to define the type of value that a vaiable hold or store

# str: string data type (text)

name = "John"

print(type(name))

<class 'str'>

# int : integer data type (number)

x = 100

print(type(x))

<class 'int'>

# float : floating-point number ( decimal number)

marks = 3.33

print(type(marks))

<class 'float'>

# bool : represent either True or False

is_raining = True

print(type(is_raining))

<class 'bool'>
Someting

keyboard_arrow_down Type Casting

type casting or type converter is a process to covert one data type into another

x = 100
y = "200"

print(str(x) + y)

print(x + int(y))

new_x = str(x)
new_y = int(y)

new_total = new_x + y
new_total1 = x + new_y

print(new_total)
print(new_total1)

100200
300
100200
300

# Write a code to find the area of rectangle

# area = length * width

length = float(input("Enter your length: "))


width = float(input("Enter your width: "))
area = length * width # formula of rectangle area

print(f"Area of rectangle is: {round(area,2)}cm^2")

Enter your length: 44.33


Enter your width: 33.45
Area of rectangle is: 1482.84cm^2

# Creating a Shopping cart

item = input("What type of item would you like? ")


price = float(input("What is the price? "))
quantity = int(input("how many items you want? "))

total = price * quantity

print()
print()

print(f"You have bought {quantity} of {item}'s")


print(f"Your total is: ${round(total,2)}")
print('Thanks')

What type of item would you like? Pizza


What is the price? 99.99
how many items you want? 3

You have bought 3 of Pizza's


Your total is: $299.97
Thanks

Start coding or generate with AI.

You might also like