Computer Science
Observe the code given below and answer the following questions:
n = ............... #Statement 1
if ............... :
#Statement 2
print ("Please enter a positive number")
elif ............... :
#Statement 3
print ("You have entered 0")
else:
...............
#Statement 4
(a) Write the input statement to accept n number of terms — Statement 1.
(b) Write if condition to check whether the input is a positive number or not — Statement 2.
(c) Write if condition to check whether the input is 0 or not — Statement 3.
(d) Complete Statement 4.
Python Control Flow
1 Like
Answer
(a) Statement 1: n = int(input("Enter a number: "))
— This statement accepts input from the user and converts it to an integer.
(b) Statement 2: if n > 0:
— This condition checks if the entered number is positive.
(c) Statement 3: elif n == 0:
— This condition checks if the entered number is zero.
(d) Statement 4: print("You have entered a negative number")
— This statement handles the case where the number is negative.
Answered By
3 Likes