Pyhton Basics (PT 2)
Pyhton Basics (PT 2)
UNIT 3
TWO (2) MARK QUESTION BANK
1. Write a Python program to accept two numbers and the greatest and
print the result.
num1, num2 = 20 , 30
if num1>num2:
print(num1)
else:
print(num2)
o/p
30
2. What is recursion?
recursion is a method of solving a computational problem where the
solution depends on solutions to smaller instances of the same problem.
Recursion solves such recursive problems by using functions that call
themselves from within their own code.
4. With the help of an example, define an array and create an array to print
your name.
An array is a collection of items stored at contiguous memory locations.
The idea is to store multiple items of the same type together. This makes
it easier to calculate the position of each element by simply adding an
offset to a base value, i.e., the memory location of the first element of
the array (generally denoted by the name of the array).
# Global scope
s = "I love Geeksforgeeks"
f()
print(s)
Output
Me too.
I love Geeksforgeeks
8. Write a Python program to accept two numbers, multiply them, and print
the result.
num_1 = int(input(“Enter the value of num_1:”))
num_2 = int(input(“Enter the value of num_2:”))
product = num_1 * num_2
print("Product of {} and {} is {}".format(num_1, num_2,product))
Output
Enter the value of num_1:2
Enter the value of num_2:3
Product of 2 and 3 is 6
X = [[1,2,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[9,8,7],
[6,5,4],
[3,2,1]]
result = [[0,0,0],
[0,0,0],
[0,0,0]]
for r in result:
print(r)
Output
[10, 10, 10]
[10, 10, 10]
[10, 10, 10]
Output
input the number one: 24
input the number one: 12
The sum is 288
myStr[start:stop:step]