0% found this document useful (0 votes)
32 views3 pages

ICT Python Worksheet Answers

Uploaded by

niaannaabraham
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)
32 views3 pages

ICT Python Worksheet Answers

Uploaded by

niaannaabraham
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/ 3

ICT Python Worksheet – Answer Key

Section I: Data Types


Given code:

movieTitle = "The Jungle Book"


releaseYear = 2016
rating = 7.4
genre = "Adventure"

Variable Name Data Type Explanation

movieTitle String A string is used to store text,


such as the title of a movie.

releaseYear Integer The year is a whole number,


so it's stored as an integer.

rating Float Decimal numbers are stored


using the float data type.

genre String The genre is a word (text),


so it is stored as a string.

Section II: Student Info


Given code:

studentName = "Ravi"
rollNumber = 1024
height = 1.45
school = "Sunrise Public School"
isPresent = True

Variable Name Data Type Explanation

studentName String The name is text, so it is


stored as a string.

rollNumber Integer Roll numbers are whole


numbers.

height Float Height can have decimals,


so float is used.

school String The school name is a string


of text.

isPresent Boolean Boolean is used for True or


False values.

Python Programs

a. Convert Temperature from Celsius to Fahrenheit


celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print("Temperature in Fahrenheit is:", fahrenheit)

b. Calculate Simple Interest


principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the rate of interest: "))
time = float(input("Enter the time in years: "))
simple_interest = (principal * rate * time) / 100
print("Simple Interest is:", simple_interest)

c. Calculate the Volume of a Cube


side = float(input("Enter the length of one side of the cube: "))
volume = side * side * side
print("Volume of the cube is:", volume)

d. Calculate BMI (Body Mass Index)


weight = float(input("Enter your weight in kg: "))
height = float(input("Enter your height in meters: "))
bmi = weight / (height * height)
print("Your BMI is:", bmi)

e. Temperature Check (Hot or Cold)


temp = float(input("Enter the temperature in Celsius: "))
if temp > 30:
print("It's hot today!")
else:
print("It's a cool day.")

f. Check if a Number is Positive, Negative or Zero


num = float(input("Enter a number: "))
if num > 0:
print("The number is positive")
elif num < 0:
print("The number is negative")
else:
print("The number is zero")

Error Detection and Correction


Code (with error) Issue Correct Code

item_price = input("Enter Input is string; cannot item_price =


the price of the item: ") multiply directly. String float(input("Enter the price
quantity = input("Enter the addition in print is of the item: "))
quantity: ") incorrect. quantity = int(input("Enter
total = item_price * quantity the quantity: "))
print("Total cost is: " + total = item_price * quantity
total) print("Total cost is:", total)

number = int(input("Enter a Used '=' instead of '=='. number = int(input("Enter a


number: ")) number: "))
if number % 2 = 0: if number % 2 == 0:
print("The number is print("The number is
even") even")
else: else:
print("The number is print("The number is
odd") odd")

pocket_money = Input is string, needs pocket_money =


input("Enter your monthly conversion. '+' in print float(input("Enter your
pocket money: ") needs to be replaced with monthly pocket money: "))
months = input("Enter comma or conversion. months = int(input("Enter
number of months: ") number of months: "))
total = pocket_money * total = pocket_money *
months months
print("Total pocket money print("Total pocket money
received is: " + total) received is:", total)

You might also like