Questions

1 Marks Quetions

🎯

Test yourself on this topic

13 questions · timed · auto-graded

Question 11 Mark
How can the range() function and for loop be used to print the numbers 10, 9, 8,..., 1 i.e. the reverse of the previous question?
Answer
For i in range(10):
print(10 - i)
View full question & answer
Question 21 Mark
How can the range() function and for loop be used to print the consecutive numbers 1, 2, 3, .... 10?
Answer
For i in range(10):
print(i + 1)
View full question & answer
Question 31 Mark
Write a Python program to show where whitespace indentation is required.
Answer
1st = [2,4,6,8]
for x in lst:
print(x,end = ' ')
In the last line of above program, whitespace indentation is used. This line is (the only one) inside the for loop.
View full question & answer
Question 41 Mark
Write a Python program to input a number, and print whether the number is zero, positive or negative.
Answer
n = int(input("Enter number:"))
if n ==0:
print("Is Zero.")
elif n > 0:
print("Is Positive.")
elif n < 0:
print("Is Negative.")
View full question & answer
Question 51 Mark
Write a Python program to take as input two numbers and print out the bigger one. The numbers are different.
Answer
a = int (input("1st number"))
b = int (input ("2nd number"))
if a > b:
print(a, " is bigger")
else:
print (b, "is bigger")
View full question & answer
Question 81 Mark
If there are two integers a and b, how can you (in one line) print the difference of the two integers, here a-b?
Answer
print (a - b)
View full question & answer
Question 91 Mark
Assume that you take two inputs a and b, as string data type. How can you print the strings as:
<string a><string b><string a>
Answer
self
View full question & answer
Question 101 Mark
How can you increase the value of a variable (which is of integer type) by 5? How can you decrease the value by 5?
Answer
self
View full question & answer