0% found this document useful (0 votes)
52 views4 pages

Python Variable Data Type Exercises

The document provides a comprehensive list of 57 exercise questions designed to help students practice various variable data types in Python, including int, float, decimal, datetime, complex, boolean, and strings. Each section contains multiple exercises that cover fundamental operations and concepts related to these data types. The exercises range from basic to advanced levels, ensuring a thorough understanding of Python's variable types.

Uploaded by

Ilyas Bacha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views4 pages

Python Variable Data Type Exercises

The document provides a comprehensive list of 57 exercise questions designed to help students practice various variable data types in Python, including int, float, decimal, datetime, complex, boolean, and strings. Each section contains multiple exercises that cover fundamental operations and concepts related to these data types. The exercises range from basic to advanced levels, ensuring a thorough understanding of Python's variable types.

Uploaded by

Ilyas Bacha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Comprehensive list of exercise questions to help students practice different

variable data types in Python, including int, float, decimal, datetime,


complex, boolean, and strings.

📌 Integer (int) Exercises


1. Declare two integer variables and perform addition, subtraction,
multiplication, and division.
2. Write a Python program to find the largest and smallest integer among
three given numbers.
3. Convert a string input to an integer and print its square.
4. Take an integer input from the user and check whether it is even or odd.
5. Create a program that asks the user for an age and prints whether they are a
minor (age < 18) or an adult.
6. Write a program to find the sum of the digits of a given integer (e.g., input:
123 → output: 6).

📌 Floating Point (float) Exercises


7. Declare two float variables and perform arithmetic operations.
8. Take a floating-point input from the user and round it to 2 decimal places.
9. Write a Python program to find the square root of a given number.
[Link] an integer to a float and display both values.
[Link] a program that converts temperature from Celsius to Fahrenheit.
[Link] the average of three float numbers entered by the user.
[Link] a Python program to check if two float numbers are equal up to two
decimal places.

📌 Decimal Data Type (from decimal module)


[Link] the decimal module and perform precise arithmetic calculations.
[Link] a float to a decimal and perform a division operation with 4
decimal places.
[Link] a program to calculate currency conversion using the decimal
module for precise results.
[Link] a program that computes the compound interest using the decimal
module.
[Link] the results of a float division and a decimal division.

📌 Complex Number Exercises


[Link] two complex numbers and perform addition, subtraction,
multiplication, and division.
[Link] the real and imaginary parts of a given complex number.
[Link] a program to find the modulus of a complex number.
[Link] two complex numbers as input and check if their real parts are equal.
[Link] a complex number to polar form using the cmath module.

📌 Boolean Exercises
[Link] two boolean variables and use AND, OR, and NOT operators.
[Link] an integer input and check if it is greater than 100 (output should be
True/False).
[Link] a Python program that returns True if a number is positive and
False if negative.
[Link] whether a given number is divisible by both 3 and 5.
[Link] a simple login system that verifies a user’s username and password
(boolean check).
[Link] a program to check if a given year is a leap year.
[Link] a user's age as input and check if they are eligible to vote (age ≥ 18).

📌 String Exercises
[Link] a user’s full name as input and print the first and last name
separately.
[Link] a program to count the number of vowels in a given string.
[Link] a string into uppercase and lowercase.
[Link] the user for a sentence and replace all spaces with hyphens.
[Link] a given string without using built-in functions.
[Link] a program that checks if a given word is a palindrome.
[Link] the user for their name and display a greeting message using f-
strings.
[Link] the domain name from an email address.
[Link] two strings and concatenate them using different methods (+, join,
format, f-string).
[Link] a program to find the longest word in a sentence.

📌 Date and Time (datetime module) Exercises


[Link] the datetime module and print the current date and time.
[Link] the day of the week for today’s date.
[Link] a user’s birthdate as input and calculate their age.
[Link] a program that checks if a given date falls on a weekend.
[Link] a date from string format ("YYYY-MM-DD") to a datetime
object.
[Link] the difference (in days) between two given dates.
[Link] the current time and format it as HH:MM:SS.
[Link] 10 days to today’s date and print the new date.
[Link] a program that displays the number of days left until New Year.
[Link] the current date into different formats (MM/DD/YYYY, YYYY-MM-DD,
DD Mon, YYYY).

🔹 Bonus: Mixed Data Type Questions


[Link] a program that asks for a name, age, and height and displays them
with appropriate types.
[Link] a Python script that takes a number (int), converts it to float, then
to a string, and prints the types.
[Link] int, float, bool, str, and complex types in a list and print each
element with its type.
[Link] a program that converts a decimal number into binary, octal, and
hexadecimal.
[Link] a string containing a date (e.g., "2025-12-25") and convert it into a
datetime object.
[Link] the user for their name and age, then print "Hello, John! You were born
in 2000." (dynamically calculated birth year).
[Link] a Python function that takes an integer, float, and string as
parameters and returns a formatted string.

This set of 57 questions covers all fundamental variable data types in Python,
providing a wide range of exercises from beginner to advanced levels.

You might also like