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

Variables Exervice

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)
1 views4 pages

Variables Exervice

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
You are on page 1/ 4

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.
10.Convert an integer to a float and display both values.
11.Write a program that converts temperature from Celsius to Fahrenheit.
12.Find the average of three float numbers entered by the user.
13.Write a Python program to check if two float numbers are equal up to two
decimal places.

📌 Decimal Data Type (from decimal module)


14.Import the decimal module and perform precise arithmetic calculations.
15.Convert a float to a decimal and perform a division operation with 4
decimal places.
16.Write a program to calculate currency conversion using the decimal
module for precise results.
17.Create a program that computes the compound interest using the decimal
module.
18.Compare the results of a float division and a decimal division.

📌 Complex Number Exercises


19.Declare two complex numbers and perform addition, subtraction,
multiplication, and division.
20.Find the real and imaginary parts of a given complex number.
21.Write a program to find the modulus of a complex number.
22.Take two complex numbers as input and check if their real parts are equal.
23.Convert a complex number to polar form using the cmath module.

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

📌 String Exercises
31.Take a user’s full name as input and print the first and last name
separately.
32.Write a program to count the number of vowels in a given string.
33.Convert a string into uppercase and lowercase.
34.Ask the user for a sentence and replace all spaces with hyphens.
35.Reverse a given string without using built-in functions.
36.Write a program that checks if a given word is a palindrome.
37.Ask the user for their name and display a greeting message using f-
strings.
38.Extract the domain name from an email address.
39.Take two strings and concatenate them using different methods (+, join,
format, f-string).
40.Write a program to find the longest word in a sentence.

📌 Date and Time (datetime module) Exercises


41.Import the datetime module and print the current date and time.
42.Get the day of the week for today’s date.
43.Take a user’s birthdate as input and calculate their age.
44.Write a program that checks if a given date falls on a weekend.
45.Convert a date from string format ("YYYY-MM-DD") to a datetime
object.
46.Find the difference (in days) between two given dates.
47.Get the current time and format it as HH:MM:SS.
48.Add 10 days to today’s date and print the new date.
49.Write a program that displays the number of days left until New Year.
50.Convert the current date into different formats (MM/DD/YYYY, YYYY-MM-DD,
DD Mon, YYYY).

🔹 Bonus: Mixed Data Type Questions


51.Create a program that asks for a name, age, and height and displays them
with appropriate types.
52.Write a Python script that takes a number (int), converts it to float, then
to a string, and prints the types.
53.Combine int, float, bool, str, and complex types in a list and print each
element with its type.
54.Write a program that converts a decimal number into binary, octal, and
hexadecimal.
55.Take a string containing a date (e.g., "2025-12-25") and convert it into a
datetime object.
56.Ask the user for their name and age, then print "Hello, John! You were born
in 2000." (dynamically calculated birth year).
57.Write 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