0% found this document useful (0 votes)
10 views

Codes Grade 11

The document contains a series of Python programming exercises that demonstrate basic programming concepts such as input/output, conditionals, loops, and functions. Each exercise includes a problem statement, a sample solution, and expected output. The topics covered range from simple arithmetic operations to pattern printing and number manipulation.

Uploaded by

Sarita Saini
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Codes Grade 11

The document contains a series of Python programming exercises that demonstrate basic programming concepts such as input/output, conditionals, loops, and functions. Each exercise includes a problem statement, a sample solution, and expected output. The topics covered range from simple arithmetic operations to pattern printing and number manipulation.

Uploaded by

Sarita Saini
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

1.

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 :

num1=int(input('enter a number : '))


num2=int(input('enter a number : '))
if(num1>num2):
print(num1,'is greater')
else:
print(num2,'is greater')

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 :

num1=int(input('enter a number : '))


num2=int(input('enter a number : '))
if(num1%num2==0):
print(num1,'is fully divisible by',num2)
else:
print(num1,'is not fully divisible by',num2)

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 :

num1=int(input('enter a number : '))


num2=int(input('enter a number : '))
num3=int(input('enter a number : '))
if(num1>num2 and num1>num3):
print(num1,'is the largest number')
elif(num2>num1 and num2>num3):
print(num2,'is the largest number')
else:
print(num3,'is the largest number')

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 :

wd=int(input('enter a weekday number : '))


if(wd==1):
print('Sunday')
elif(wd==2):
print('Monday')
elif(wd==3):
print('Tuesday')
elif(wd==4):
print('Wednesday')
elif(wd==5):
print('Thursday')
elif(wd==6):
print('Friday')
elif(wd==7):
print('Saturday')
else:
print('Not a valid day')

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 :

mn=int(input('Enter a month number : '))


if(mn>=3 and mn<=6):
print('Summer')
elif(mn>=7 and mn<=10):
print('Rainy')
elif(mn==11 or mn==12 or mn==1 or mn==2):
print('Winter')
else:
print('Not a valid month')

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 :

num1=float(input('Enter a number : '))


num2=float(input('Enter a number : '))
ch=input('Enter a choice+,-,/,*')
if(ch=='+'):
num3=num1+num2
print('Addition is : ',num3)
elif(ch=='-'):
num3=num1-num2
print('Subtraction is : ',num3)
elif(ch=='*'):
num3=num1*num2
print('Multiplication is : ',num3)
elif(ch=='/'):
num3=num1/num2
print('Division is : ',num3)

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 :

ch = input('Enter a character : ')


if(ch.isalpha()):
print('Is an alphabet')
if(ch.isupper()):
print('Uppercase : ', ord(ch))
else:
print('Lowercase : ', ord(ch))
else:
print('Not an alphabet')

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 :

name=input('Enter your name : ')


num=len(name)
while(num>0):
print(name[0:num])
num=num-1

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

You might also like