Built in Data Type
Built in Data Type
Built in Data Type
• Type casting is converting the data type of a value to another data type.
• In programming, it is sometimes needed to change the data type of
information. This is known as type casting.
A word of caution: trying to cast a string of text into an integer or float will cause
an error! Try int(“hello”) and see what happens!
Note: You cannot convert complex numbers into another number type.
Type Casting
x=1 #int
y=2.5 #float
z=“33” #str
print(x) print(str(x))
print(y) print (int(x))
print(z) print (float(x))
print(3*z)
z=int(z)
print(3*z)
Accepting user Input
width=int(input("width of rectangle"))
length=int(input("length of rectangle"))
high=int(input(“high of rectangle"))
volume= length * width*high
print("The volume of rectangle is : ", volume ,
“cubic meter")
Exercise
Area of Circle
Built-in Data Types
• It contains a body of code which runs only when the condition given in the
if statement is true.
• If the condition is false, then the optional else statement runs which
contains some code for the else condition.
IF…Else Flowchart
age=int(input("How old are you?"))
if age>=18:
print("You are an adult")
else:
print("You are a child")
If-elif-else
and operator: The Result is only True when both the First Value and the
Second Value are True.
or operator: The Result is True if the First Value is True, or if the Second
Value is True, or if both values are True.
not operator: The Boolean ‘not’ operator returns the logical opposite, so that
not True is False, and not False is True.
What about the Boolean ‘and’ operator? What Results would we get below?
First Value Second Value Result
False False
False True
True False
True True
What about the Boolean ‘or’ operator? What Results would we get below?
First Value Second Value Result
False False
False True
True False
True True
What about the Boolean ‘not’ operator? What Results would we get below?
Value Result
not True
not False
temp=int(input("What is the temperature outside?"))
if temp >= 0 and temp <= 30:
print("The temperature is good today!")
print("Go outside")
else temp<0 or temp>30:
print("The temperature is bad today")
print("Stay inside")
temp=int(input("What is the temperature outside?"))
if not(temp >= 0 and temp <= 30):
print("The temperature is bad today")
print("Stay inside")
else:
print("The temperature is good today!")
print("Go outside")