1.
Python writes data on screen using which function?
Correct Answer
C. Print()
Explanation
The correct answer is print(). In Python, the print() function is used to write data on the screen. It is a built-in function that allows us to display output to the console. By passing the desired data or variables as arguments to the print() function, we can easily output them to the screen.
2.
Python can recognise this data: "hello"
Correct Answer
A. Yes
Explanation
Python can recognize the data "hello" because it is a string literal enclosed in quotation marks. In Python, strings are a built-in data type and can be defined using single quotes ('hello') or double quotes ("hello"). The given data is enclosed in double quotes, which is a valid way to define a string in Python. Therefore, Python can recognize and interpret the given data as a string.
3.
Python can recognise this data: 56.97
Correct Answer
A. Yes
Explanation
Python can recognize the data "56.97" because it is a valid floating-point number. In Python, floating-point numbers are represented with a decimal point, allowing for both whole numbers and fractions. The given data follows this format, making it recognizable by Python.
4.
Python can recognise this data: computer
Correct Answer
C. Sometimes
Explanation
Python can sometimes recognize the data "computer" depending on the context and how it is used. Python is a versatile programming language that can handle various types of data, including strings like "computer". However, the recognition of this data may depend on the specific program or code being written in Python. In some cases, Python may not be able to recognize the data if it is not properly formatted or if it is used in a way that is not supported by the language. Therefore, the answer is "Sometimes".
5.
Python can recognise this code: 3 + 6 * 8
Correct Answer
A. Yes
Explanation
Python can recognize and evaluate mathematical expressions using the correct order of operations. In the given code, 3 + 6 * 8, Python will first multiply 6 by 8, resulting in 48, and then add 3 to it, resulting in 51. Therefore, Python can recognize and evaluate this code correctly.
6.
In Python, the _______ statement is used to terminate a loop prematurely.
Correct Answer
break, Break, BREAK
Explanation
The break statement is used to exit a loop (e.g., for loop or while loop) before it has completed all its iterations. When the break statement is encountered within a loop, the loop terminates immediately, and the program execution continues with the next statement after the loop. This can be useful for situations where you want to exit a loop based on a certain condition or when you have found the desired result within the loop.
7.
Python will run this program without errors: print("hello")
Correct Answer
A. True
Explanation
The given program consists of a single line of code that uses the print() function to display the string "hello". This is a valid Python syntax and will run without any errors. Therefore, the correct answer is True.
8.
Python will run this program without errors: print(765.9908)
print("that was a number")
Correct Answer
A. True
Explanation
The given program consists of two print statements. The first print statement prints a floating-point number, 765.9908. Since there are no syntax errors or any other issues in this statement, Python will execute it without any errors. The second print statement prints a string, "that was a number". Again, there are no errors in this statement. Therefore, Python will run this program without any errors, resulting in the correct answer being True.
9.
The output of this program will be? print("5+7+2")
Correct Answer
C. 5+7+2
Explanation
The output of this program will be "5+7+2". This is because the print statement is printing the exact string "5+7+2" as it is, without evaluating the expression. Therefore, the output will be the string itself, not the result of the addition.
10.
What will the output of this program be?
print("Hello")
text = "This is a number"
print("Hi, " + text)
number = 4
print(box + 2)
print(box * 2)
print(box * box - box)
Correct Answer
A. Hello Hi, This is a number
Explanation
The program will output "Hello" and "Hi, This is a number" successfully. However, it will encounter an error at print(box + 2) because the variable box is not defined anywhere in the program. This will stop the program's execution before it can reach the subsequent print statements involving box. Thus, the output will include the first two print statements, followed by an error due to the undefined variable box.
11.
This program will run without errors: print(x)
x = 3
print(x+3)
Correct Answer
B. False
Explanation
The program will not run without errors because the variable x is being printed before it is assigned a value. When the print(x) statement is encountered, x has not been defined yet, resulting in an error.
12.
What structure do you use to let the computer make decisions in Python?
Correct Answer
B. If statement
Explanation
In Python, the if statement is used to let the computer make decisions. It allows the program to execute a certain block of code only if a specific condition is true. The if statement evaluates the condition and if it is true, the code inside the if block is executed. Otherwise, it is skipped. This decision structure is fundamental in programming as it allows for different actions to be taken based on different conditions.
13.
What optional part can you add to an if statement?
Correct Answer
B. Else
Explanation
An optional part that can be added to an if statement is the "else" clause. This allows for an alternative block of code to be executed if the condition in the if statement evaluates to false. The code within the else block will be executed when the condition is not met, providing an alternative path of execution.
14.
Which of these could python run without errors?
Correct Answer
D. Neither
Explanation
The correct syntax in Python for using an "if" statement with a one-liner is to include a colon after the condition. Therefore, the correct way to write this statement is:
x = 5 if x < 10: print("hi")
Therefore, the correct answer is neither.
15.
This program is full of errors. What do you need to change to make it correct?cat_weight = 45
if cat_wieght = 50;
print your cat is healthy
else:
print unhealthy
Correct Answer(s)
A. The variable name has been spelled wrong
C. If statements end in a colon, not semicolon
D. Instructions underneath an if and an else should be indented by 4 spaces
F. Words that python should understand should be "surrounded by quotes".
I. Print() should always be written with brackets
J. You should use ==, not = to check if two things are equal
Explanation
The correct answer is: The variable name has been spelled wrong. You should use ==, not = to check if two things are equal. If statements end in a colon, not semicolon. print() should always be written with brackets. Words that python should understand should be "surrounded by quotes". Instructions underneath an if and an else should be indented by 4 spaces.
The given program contains multiple errors. First, the variable name "cat_wieght" has been spelled wrong, it should be "cat_weight". Second, the equality check in the if statement should use == instead of =. Third, if statements in Python end with a colon, not a semicolon. Fourth, the print() function should always be written with brackets. Fifth, words that Python should understand, like "healthy" and "unhealthy", should be surrounded by quotes. Lastly, the instructions underneath the if and else statements should be indented by 4 spaces to indicate that they are part of the respective blocks.