Python Type Conversion

πŸ“Œ Python Type Conversion β€” Beginner Assignments

1) Integer to Float

Create a variable num = 10. Convert it to a float and print the new value and its type.


2) Float to Integer

Create value = 9.99. Convert it to an integer and print the result and its type.


3) String to Integer

Create num_str = "123". Convert it to an integer and print the value and type.


4) String to Float

Create price = "45.67". Convert to float and print.


5) Integer to String

Create x = 2026. Convert it to a string and print both type and value.


6) Boolean to Integer

Create flag = True. Convert it to integer and print.


7) Boolean to String

Create flag = False. Convert to string and print.


8) Float to String

Create temp = 36.6. Convert to string and print length of the new string.


9) String to Boolean

Create val = "True". Convert to boolean and print.


10) Combination Conversion

Create:

Convert a to integer, add to b, and print the result.


11) Input Conversion

Ask the user for their age using input() (which returns string). Convert it to integer and print a message: Your age next year will be: <age + 1>


12) Convert List Length to String

Create a list of 4 elements. Get its length and convert that number to string, then print.


13) Concatenate Number & String

Create:

Convert num to string and concatenate with txt. Print result.


14) Safe Conversion

Create value = "abc". Try converting it to integer inside a try/except. If error occurs, print: Conversion Failed

(No need for advanced error handling β€” basic try/except is enough.)


15) Convert Input to Float

Ask user to input a number with decimal. Convert to float and print half of that number.


16) Tuple to List Conversion

Create t = (1, 2, 3). Convert it to a list and print.


17) List to Tuple Conversion

Create l = [4, 5, 6]. Convert to tuple and print.


18) String of Numbers to List

Create s = "12345". Convert it to a list of characters and print.

Expected:


19) List of Strings to Integers

Create lst = ["1", "2", "3"]. Convert each element to integer and print the new list.


20) Numeric Calculation with Conversion

Create:

Convert both to floats, add them, and print the result.


πŸ“ Bonus Challenge (Optional)

Use type conversion to format this sentence:

Print:


canvil: 333f6c7d-6876-4f7e-b6ad-1bdb2233f5c1

Last updated