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

4.2-4.6 QA Computer jr2

Uploaded by

deadx77op
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

4.2-4.6 QA Computer jr2

Uploaded by

deadx77op
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

42-4.6.

Question Answers

1. What does 'exit condition' mean?


answer: An exit condition is a specific criterion or a condition in a loop or process that, when
met, causes the loop to stop executing.
2. What are the two types of loops?
answer: The two main types of loops in programming are:
For Loop: Repeats a specific number of times, typically iterating over a range or sequence.
While Loop: Repeats as long as a specified condition remains true.
3. Write the first line of a Python loop that repeats 100 times.
answer: for i in range(100):
4. a) Here is a Python program. It has an error in it. Explain what the error is.
print("Start program")
while username != "x"
username= input("enter your name )
print("hello", username)
Answer
1. Variable username is not initialized: The variable username is used before
being assigned a value.
2. colon : in second line
3. " inverted comma
b) Write the program without the error
Answer
print("Start program")
username = ""
while username != "x":
username = input("Enter your name ")
print("hello", username)
5. Name one place in a Python program where you must include a colon.
a) After a conditional statement:
if condition:
b) After a loop declaration:
while True:
6. Explain the difference between a single equal sign and a double equal sign in
python.

Single Equal Sign (=):

 Purpose: Used for assignment. It assigns a value to a variable.

Example: x = 5 # Assigns the value 5 to the variable x

Double Equal Sign (==):

 Purpose: Used for comparison. It checks whether two values are equal.
 Example: if x == 5: # Compares whether x is equal to 5 print("x is 5")

7. Why is it harder for a programmer to spot a logical error than a syntax error?

Syntax errors are easier to identify because the Python interpreter highlights them
immediately when you run the program, indicating where the issue is.

Logical errors, on the other hand, occur when the program runs without errors but produces
incorrect or unintended results. These errors require the programmer to manually debug and
trace the logic to identify what went wrong.

8. Write a Python program that adds together five numbers input by the user.

total = 0

for i in range(5):

number = int(input("Enter a number: "))

total += number

print("The total is:", total)

output

Enter a number: 1

Enter a number: 3

Enter a number: 2

Enter a number: 6

Enter a number: 7

The total is: 19

You might also like