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

Ict Homework

Uploaded by

kokatemaryam10
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)
23 views4 pages

Ict Homework

Uploaded by

kokatemaryam10
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

Computing Homework

Topic: Python Programming

Name: Erica Sam

Question 1: Match the Following


Match the relational operators in Python with their corresponding functions.

Column A Column B

1. < A. Greater than

2. <= B. Equal to

3.> C. Greater than or equal


to

4. == D. Less than or equal to


5. >= E. Less than

Question 2: Predict the Output (4 Marks)


For each of the following code snippets, predict the output.
a. A = 123
print(‘A’)
Output: A____________________________________________

b. Abc = ‘ICT’
print(Abc)
Output: ICT___

c.
P = “Python"
print("P")
Output__P_______________________________________________________

d. A = "232"
print('A')
Output____A_________________________________________________

Question 3: Complete the Python Program Code


a. Complete the Python code to read your name and display it.
X= (“Enter your name: “)
print (X)
b. Complete the Python code to read a number and display it.

X=int (input(“Enter a number”))


print(X)

c. Complete the Python code to read the length and width. Display the area
of the rectangle.
L= int(input(“Enter the length”))
W=int(input(“Enter the width”))
Area=L*W
Print(Area)

d. Write a Python program to read two numbers from the user and display
their sum.(Hint: Perform addition)
m=int(input(“Enter first number”))
s=int(input(“Enter second number”))
k=s+m
print(l)

e. Write a Python program to read a number. Add 10 to the number and


display it.
x=int(input(“Enter a number”))
a=x+10
print(a)

Question 4: Find the Error


Identify the errors in the following Python code snippets and rewrite the
corrected code:
a. X = "Hello
print(X)
Error: Missing quotation

Correction: X = "Hello”

b. P = 5678
print(p)
Error: p should be capital

Correction: print(P)
c. X=123
print=(X)
Error: There shouldn’t be a = sign

Correction: print(X)

d. A = "Python"
Print(A)
Error: The P in print shouldn't be capital

Correction: print(A)

Question 5: Critical thinking


a. Saira creates a Python program to read and display her name and age.

Her code is:

name=int(input(“Enter your name”))


age=int(input(“Enter your age”))
print(name)
print(age)

Is her code correct? Justify your answer.


b. No, The input() function always returns a string, but int(input("Enter
your name")) tries to convert the name into an integer, which will
cause an error. .

c. Kevin creates a Python program to multiply 2 numbers as shown below.


A=”123”
B=”12”
C=A*B
print(C)
Is his code correct? Justify your answer.

A and B are strings, and C = A * B will cause an error since string


multiplication with another string is not allowed . So u convert the
strings to integers before multiplication

d. While running the Python program below, Neha got the output as 17
not 30. Why?

print (2+5*3)
because we multiply first and then add, so 5×3 is 15, and 15+2=17. If
Neha wants the answer to be 30, she should change the + to *, so it
becomes 2*5*3. First, 2×5=10, and then 10×3=30.

You might also like