Python Worksheet: Data Types (Integer, String, Float)
Instructions
This worksheet contains 10 questions to practice working with Python data types: integer,
string, and float. Each question requires you to write a Python program that demonstrates a
practical use case. Use the input() function to collect user input and display the output as
specified. Assume all inputs are valid numbers or strings. Do not use if-else, loops, or any
control structures. All formulas for calculations are provided.
1 Questions
1. Integer: Number of Students
Prompt the user for the number of students in a class (integer). Display: “The class has
[number] students.”
2. String: Event Name
Take the name of an event (string) as input. Display: “The event is ’[name]’.”
3. Float: Speed Calculator
Ask the user for distance (float, in kilometers) and time (float, in hours). Calculate speed
using the formula: speed = distance/time. Display: “The speed is [speed] km/h.”
4. Integer: Total Pages
Prompt the user for the number of pages in a book (integer). Display: “The book has
[pages] pages.”
5. String: Product Code
Take a product code (string) as input. Display: “The product code is [code].”
6. Float: Area of a Rectangle
Ask the user for the length (float) and width (float) of a rectangle. Calculate the area
using the formula: area = length × width. Display: “The area of the rectangle is [area]
square units.”
7. Integer: Items Purchased
Prompt the user for the number of items purchased (integer). Display: “You purchased
[number] items.”
8. Float: Simple Interest
Take the principal amount (float), interest rate (float, as a percentage), and time (float, in
years) as input. Calculate simple interest using the formula: SI = (principal × rate ×
time)/100. Display: “The simple interest is [interest].”
9. String: City Name
Take the name of a city (string) as input. Display: “The city is ’[name]’.”
10. Float: Temperature Converter
Ask the user for a temperature in Celsius (float). Convert it to Fahrenheit using the
formula: F = (C × 9/5) + 32. Display: “The temperature in Fahrenheit is [fahrenheit].”