Codes Grade 11
Codes Grade 11
Write a python program to take 2 numbers from user and print total
of numbers.
Answer:
def add():
num1= int(input('Enter a number : '))
num2= int(input('Enter a number : '))
num3 = num1+num2
print('Result is : ', num3)
add()
Output:
Enter a number : 20
Enter a number : 40
Result is : 60
2. Write a python program to take a number as input. Check and print
appropriate message for even of odd number
Answer :
def even_odd():
num1=int(input('enter a number : '))
if(num1%2==0):
print('even number')
else:
print('odd number')
even_odd()
Output:
Enter a number : 20
Even number
3. Write a python program to take 2 numbers as input and print greater
number as output
Answer :
Output:
Enter a number : 20
Enter a number : 40
60 is greater
4. Write a python program to take 2 numbers as input and check if
number 1 is fully divisible by number 2 or not. Display appropriate
message as output.
Answer :
Output:
Enter a number : 20
Enter a number : 3
20 is not fully divisible by 3
5. Write a python program to take 3 numbers as input and display
largest number as output.
Answer :
Output:
Enter a number : 20
Enter a number : 40
Enter a number : 35
40 is the largest number
6. Write a python program to take 1 number as input and display
weekday name as output.
[hint : 1 – Sunday, ………………. 7 – Saturday]
Answer :
Output:
Enter a weekday number : 2
Monday
7. Write a python program to take 1 number as input. Check and display
name of season as output.
[ Hint : Month 3,4,5,6 – Summer
Month 7,8,9,10 – Rainy Season
Month 11,12,1,2 – Winter]
Answer :
Output:
Enter a month number : 2
Winter
8. Write a python program to take 2 number as input. Also take a
choice of operation(+ or – or * or /) to perform on numbers entered.
Display result after calculation.
Answer :
Output:
Enter a number : 20
Enter a number : 40
Enter a choice : +
Addition is : 60
9. Write a python program to take a character as input. Check if it is
an uppercase or lowercase alphabet and also display ASCII code of
alphabet entered.
Answer :
Output:
Enter a character : A
Is an alphabet
Uppercase : 65
10. Write a python program to take 1 number as input and display
multiples of number.
Answer :
def tabs():
num=int(input("Enter a number : "))
for sn in range(1,11,1):
print(num*sn)
tabs()
Output :
Enter a number : 2
2
4
6
8
10
12
14
16
18
20
11. Write a python program to take a character as input and display it
in following pattern.
*
**
***
****
*****
Answer :
def stars():
ch=input("Enter a character = ")
for sn in range(1,6,1):
print(ch*sn)
stars()
Output:
*
**
***
****
*****
12. Write a python program to take a name as input and display it in
following pattern.
Manish
Manis
Mani
Man
Ma
M
Answer :
Output :
Enter your name : Manish
Manish
Manis
Mani
Man
Ma
M
13. Write a python program to display output in following pattern.
0
1
0
1
0
1
0
1
0
1
Answer :
def loop01():
for num in range(2,11,1):
print(num%2)
loop01()
Output:
0
1
0
1
0
1
0
1
0
1
14. Write a python program to take a number as input and display
output in following pattern.
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30
Answer :
#while loop
num=int(input('Enter a number:'))
step=1
while(step<11):
print(num,'*',step,'=',num*step)
step=step+1
# for loop
num=int(input('Enter a number:'))
step=1
for step in range(1,11,1):
print(num,'*',step,'=',num*step)
Output :
Enter a number:3
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30
15. Write a python program to take a name as input and display it in
following pattern.
Manish
anish
nish
ish
sh
h
Answer :
#while loop
name = input('enter a name : ')
num = 0
while(num<len(name)):
print(name[ num : ])
num = num+1
#for loop
name = input('enter a name : ')
for num in range(0,len(name),1):
print(name[ num : ])
Output:
Manish
anish
nish
ish
sh
h
16. Write a python program to take a name as input and display it in
following pattern.
M
Ma
Man
Mani
Manis
Manish
Answer :
#while loop
num=0
name= input("Enter your name:")
while(num<len(name)):
print(name[ :num+1])
#for loop
num=0
name= input("Enter your name:")
for num in range(0, len(name), 1):
print(name[ :num+1])
Output:
Manish
anish
nish
ish
sh
h
17. Write a python program to display output in following pattern.
1
2
3
4
5
10
9
8
7
6
Answer :
#while loop
num= 1
while(num<11):
if (num<6):
print(num)
else:
print(16-num)
num=num+1
#for loop
num= 1
for num in range(1, 11, 1):
if (num<6):
print(num)
else:
print(16-num)
Output :
1
2
3
4
5
10
9
8
7
6
18. Write a python program to display output in following pattern.
10
9
8
7
6
1
2
3
4
5
Answer :
#while loop
num= 10
while(num>0):
if (num>5):
print(num)
else:
print(6-num)
num=num-1
#for loop
num= 10
for num in range(10, 0, -1):
if (num>5):
print(num)
else:
print(6-num)
Output:
10
9
8
7
6
1
2
3
4
5
19. Write a python program to display output in following pattern.
*
* *
* * *
* * * *
* * * * *
Answer :
def pyr1():
for num in range(1,6,1):
print('*' * num)
pyr1()
Output:
*
* *
* * *
* * * *
* * * * *
20. Write a python program to display output in following pattern.
*
**
***
****
*****
Answer :
def pyr2():
for num in range(1,6,1):
for a in range(5,num,-1):
print(' ', end='')
print('*' * num)
pyr2()
Output:
*
**
***
****
*****
21. Write a python program to display output in following pattern.
*
* *
* * *
* * * *
* * * * *
Answer :
def pyr3():
for num in range(1,6,1):
for a in range(5,num,-1):
print(' ', end='')
print('* ' * num)
pyr3()
Output:
*
* *
* * *
* * * *
* * * * *
22. Write a python program to display output in following pattern.
1
12
123
1234
12345
Answer :
def pyr4():
step=0
for num in range(1,6,1):
step = step * 10 + num
print(step)
Output :
1
12
123
1234
12345