#Python Solution All Text Programming Knowledge Based Qusetions for CBSE Board Class 11
Hi I'm Mr. Chanchal Sarkar. Here we give some codes on python Programming on Chapter Python Fundamentals for CBSE Class 11 ........
My Youtube Video link also:
Chapter 6 : Python Fundamentals
# 1) WAP that displays a joke. But display the
punchline only when the user press enter key.
Ans:
print('Start Jokinhttps://youtu.be/qRHvKxn_ANoQBasic Linkg...')
input()
print('New Kids Jokes.....
he he ha ha .....')
input()
print('Two ants want to
fight an elephant.')
input()
print('The elephant
replies: “Two on one? That’s not fair!”')
print()
print('Teacher asks the
student: “Why are you so late?!”')
input()
print('Student: “Well I
was crossing the road and suddenly it says “School ahead, go slowly!”')
print()
print('How does a school
differ from an insane asylum?')
input()
print('Different phone
numbers.')
input()
print('The
End')
# 2) Accept a date in DD MM YYYY format by the user
except leap year (february month) & display the remaining days.
Output:
Enter date in DD MM YYYY format : 14 11 2019
Days left : 16
Ans:
d, m, y = map(int,
input('Enter date in DD MM YYYY format : ').split())
mon = {1:31, 2:28, 3:31,
4:30, 5:31, 6:30, 7:31, 8:31, 9:30, 10:31, 11:30, 12:31}
print('Days
left : ', mon[m]-d)
# 3) Show current date and time, year, month, week
number, weekday, no. of days, day of month and day of the week.
Output:
Current date and time:
2019-11-14 09:41:26.345770
Current year:
2019
Month of year:
November
Week number of the year: 45
Weekday of the week:
4
No. of Days in the year: 318
Day of the month :
14
Day of week:
Thursday
Ans:
import time
import datetime
print("Current date
and time: " , datetime.datetime.now())
print("Current year:
", datetime.date.today().strftime("%Y"))
print("Month of year:
", datetime.date.today().strftime("%B"))
print("Week number of
the year: ", datetime.date.today().strftime("%W"))
print("Weekday of the
week: ", datetime.date.today().strftime("%w"))
print("No. of Days in
the year: ", datetime.date.today().strftime("%j"))
print("Day of the
month : ", datetime.date.today().strftime("%d"))
print("Day
of week: ", datetime.date.today().strftime("%A"))
# 4) WAP that generates the following output:
5
10
9
Assign value 5 to a variable using assignment
operator(=) Multiply it with 2 to generate 10 and subtract 1 to generate 9.
Ans:
a=5
b=a*2
c=b-1
print(a)
print(b)
print(c)
# 5) Modify above (no. 4 program) program so as to print
output as 5@10@9.
Ans:
a=5
b=a*2
c=b-1
print(a,"@",b,"@",c)
# 6) Write a python program that accepts radius of a
circle and prints its area.
Ans:
r=float(input("Enter
radius of the circle : "))
A=3.14*r*r
print("Area
: ", A)
# 7) Write Python program that accepts marks in 5
subjects and outputs average marks.
Ans:
a=float(input("Enter
subj1 marks : "))
b=float(input("Enter
subj2 marks : "))
c=float(input("Enter
subj3 marks : "))
d=float(input("Enter
subj4 marks : "))
e=float(input("Enter
subj5 marks : "))
avg = (a+b+c+d+e)/5
print("Average
of 5 subject marks : ", avg)
# 8) Write a short program that asks for your height
in centimetres and then converts your height to feet and inches.
(
1 foot = 12 inches, 1 inch = 2.54 cm ).
Output:
Enter your height in cm: 100
Height is 3.0 ft and 3.37 inch
Ans:
height_cm = float(input("Enter
your height in cm: "))
# Convert height to inches
height_in = height_cm /
2.54
# Get feet by taking floor
division with 12
feet = height_in // 12
# Get inches by taking
modulo division with 12
inches = height_in % 12
# Round off the inches to
2 decimal places
inches_rounded =
format(inches, ".2f")
# Print out the height in
feet and inches
print(f"Height
is {feet} ft and {inches_rounded} inch")
# 9) The real
floor division operator is “//”. It returns floor value for both integer and
floating point arguments.
Output:
2
-3
2.0
-3.0
Ans:
#
"//" for both integers and floating points
print(5//2)
print(-5//2)
print(5.0//2)
print(-5.0//2)
# 10) Formatted
string literals (f-strings)
Note: * A
new string formatting mechanism known as Literal String
Interpolation or more commonly as F-strings (because
of the leading f character preceding the string literal).
* To create an f-string, prefix the
string with the letter “ f ”.
Output:
Enter your name : Chanchal Sarkar
Enter your age : 120
Hello, My name is Chanchal Sarkar and I'm 120 years
old.
Ans:
# introducing f-string
nm=input("Enter your
name : ")
age=int(input("Enter
your age : "))
print(f"Hello,
My name is {nm} and I'm {age} years old.")
# 11) Basic
formatting with format().
The format() method allows the use of simple
placeholders for formatting.
Output:
Hello CS, your balance is 230.23
Hello CS, your balance is 2000.5
Hello CS, your balance is 12500.0
Hello CS, your balance is 60500.25
Ans:
# Basic formatting for
default, positional and keyword arguments
# default arguments
print("Hello {}, your
balance is {}".format("CS", 230.23))
# positional arguments
print("Hello {0},
your balance is {1}".format("CS", 2000.50))
# keyword arguments
print("Hello {name},
your balance is {blc}".format(name="CS", blc=12500.00))
# mixed arguments
print("Hello
{0}, your balance is {blc}".format("CS", blc=60500.25))
# 12) WAP to read a number n and print n2,
n3 and n4.
Output:
Enter a no. : 5.0
Value of n^2:
25.0
Value of n^3:
125.0
Value of n^4:
625.0
Ans:
import math
n=float(input("Enter
a no. : "))
a=math.pow(n,2)
b=math.pow(n,3)
c=math.pow(n,4)
print("Value of n^2:
",a)
print("Value of n^3:
",b)
print("Value
of n^4: ",c)
# 13) WAP to find area of a rectangle.
Output:
Enter length of Rectangle : 4
Enter Breadth of Rectangle : 8
Area is : 32.0
Ans:
L=float(input("Enter
length of Rectangle : "))
B=float(input("Enter
Breadth of Rectangle : "))
A = L*B
print(f"Area
is : {A}")
# 14) WAP to compute simple interest and compound
interest.
Output:
Enter the principal amount: 100000
Enter the interest rate: 12
Enter the time in years: 5
Simple interest :
60000.0
Compound amount :
176234.16832000008
Compound interest :
76234.16832000008
Ans:
p =
float(input("Enter the principal amount: "))
r =
float(input("Enter the interest rate: "))
t =
float(input("Enter the time in years: "))
# Simple Interest
Calculation
SI=(p*r*t)/100
# Compound Interest
Calculation
CI = p * (pow((1 + r /
100), t))
I = CI - p
print("Simple
interest : ", SI)
print("Compound
amount : ", CI)
print("Compound
interest : ", I)
# 15) WAP to input a number and print its first five
multiples in list.
Output:
Enter your number: 6
[6, 12, 18, 24, 30, 36]
Ans:
n = int(input('Enter your
number: '))
print([i*n
for i in range(1,n+1)])
# 16) WAP to read details like name, class, age of a
student and then print the details firstly in same line and then in separate
lines. Make sure to have two blank lines in these two different types of
prints.
Output:
Enter Student name : CS
Enter Student class : 11
Enter Student's age : 17
Student name :
CS -Student class : 11 -Student
age : 17
Student name :
CS
Student class :
11
Student age :
17
Ans:
name = input("Enter
Student name : ")
cl = int(input("Enter
Student class : "))
age =
int(input("Enter Student's age : "))
print("Student name :
",name,"-Student class : ",cl,"-Student age : ",age)
print()
print()
print("Student
name : ",name,"\nStudent class : ",cl,"\nStudent age :
",age)
# 17) WAP to input a single digit(n) and print a 3
digit number created as <n(n + 1)(n + 2)> e.g., if you input 7, then it
should print 789. Assume that the input digit is in range 1-7.
Output:
Enter a single digit number: 5
The three digit number is : 567
Ans:
n = int(input("Enter
a single digit number: "))
if n>0 and n<8:
a = n + 1
b = n + 2
d = (n*100) + (a*10) + b
print("The three digit number is
:", d)
else:
print("invalid input")
# 18) WAP to read 3 numbers in 3 variables and swap
first two variables with the sums of first and second, second and third numbers
respectively.
Output:
Enter the first number : 2
Enter the second number : 5
Enter the third number : 10
Numbers before swaping of first and second number
: 2 5
Numbers after swaping of first and second number
: 5 2
Numbers before swaping of second and third number
: 2 10
Numbers after swaping of second and third number
: 10 2
Ans:
a=int(input("Enter
the first number : "))
b=int(input("Enter
the second number : "))
c=int(input("Enter
the third number : "))
############################################################
print("Numbers before
swaping of first and second number : ",a,b)
a=a+b
b=a-b
a=a-b
print("Numbers after
swaping of first and second number : ",a,b)
############################################################
print("Numbers before
swaping of second and third number : ",b,c)
b=b+c
c=b-c
b=b-c
print("Numbers
after swaping of second and third number : ",b,c)


Comments
Post a Comment