Practice Problems for data types

Problem -1
Add two different data types and store the result in a variable and see if the Python compiler is able to convert the data type of the resultant variable or not.

Problem 2- The int() function can be useful to convert

A- string to Integer
B-hexadecimal to integer
C-float to int
D-Complex number to int

Regards
Utkarsh Kesharwani

5 Likes

A-strings to integers

1 Like

A - string to integer

Problem 1:

string= “12”
num = 23
number1 = int(string) #convertion string “12” into integer 12
addition = num + number1
print(“addition is” ,addition)

Problem 2:
A- string to Integer

1 Like

Problem - 1:

Number_1=5
Number_2=input("Enter any number: ")
Number = Number_1 + int(Number_2)
print("The new number is ", Number)
Number = str(Number)
print(type(Number))

Problem - 2:

A and C

1 Like

for problem 1
python compiler will not convert the data type of the resultant variable
we have to convert the data type for addition

for problem 2
The int() function can be useful to convert for all four options (except some cases user is ok with float number output then we can’t consider the option C)

1 Like

Problem 1:

string= “12”
num = 23
number1 = int(string) #convertion string “12” into integer 12
addition = num + number1
print(“addition is” ,addition)

Problem 2:
A- string to Integer

1 Like

#1 string=‘12’
integer=23
string=int(string)
sum=integer + string
print(“sum:”,sum)
print(“datatype of sum:”,type(sum))

1 Like

P-2 : A -string to integer

1 Like

Good @baba.dudekula786

First Problem:
str_1= “12”
num_1 = 23
num_2 = int(str_1)
sum = num_1 + num_2
print(sum)

Second Problem:
A: String to Integer

1 Like

#problem1
string = “12”
integer = 15
number = int(string) + integer
print (number)