Xi Assignment Beginning With Python Programing 04082024 222527
Xi Assignment Beginning With Python Programing 04082024 222527
i Serial_no. v Total_Marks
ii 1st_Room vi total-Marks
iii Hundred$ vii _Percentage
iv Total Marks viii True
2. Write the corresponding Python assignment statements:
i) Assign 10 to variable length and 20 to variable breadth.
Length=10
Breadth=20
ii) Assign the average of values of variables length and breadth to a variable sum.
Sum=(length+breadth)/2
iii) Assign a list containing strings ‘Paper’, ‘Gel Pen’, and ‘Eraser’ to a variable stationery.
iv) Assign the strings ‘Mohandas’, ‘Karamchand’, and ‘Gandhi’ to variables first, middle and last.
First=”mohandas”
v) Assign the concatenated value of string variables first, middle and last to variable fullname.
Make sure to incorporate blank spaces appropriately between different parts of names.
3. Write the output of the following:
num1 = 4
num2 = num1 + 1 4+15
num1 = 2 2
print (num1, num2)
2 5
4. num1, num2 = 2, 6
num1, num2 = num2, num1 + 2 num16 num28
print (num1, num2)
5. num1, num2 = 2, 3
num3, num2 = num1, num3 + 1
print num1, num2, num3
6. Which data type will be used to represent the following data values and why?
i. Number of months in a year => int
ii. Resident of Delhi or not =>boolean
iii. Mobile number => str / int
iv. Pocket money => float/int
v. Volume of a sphere => float
vi. Perimeter of a square =>float/int
vii. Name of the student => string
viii. Address of the student => string
7. Give the output of the following when num1 = 4, num2 = 3, num3 = 2
i. num1 += num2 + num3 num1=num1+num2+num3
print (num1) =>9
ii. num1 = num1 ** (num2 + num3)
print (num1) => 1024
iii. num1 **= num2 + num3 => num1 = num1 ** (num2+ num3)
print(num1) =>1024
iv. num1 = '5' + '5'
print(num1)
v. print(4.00/(2.0+2.0)) =>1
vi. num1 = 2+9*((3*12)-8)/10 2+9*28/10 2+252/10 2+25.2 27.2
print(num1)
vii. num1 = 24 // 4 // 2
print(num1)
viii. num1 = float(10)
print (num1) => 10.0
ix. num1 = int('3.14') =>error because string contains float value
num1 = int(‘314’)
print (num1) => 314 will be printed
num1=3.14
num2=int(3.14)
print(num2) => 3 will be printed
1. Program to ask admission number, name and age from user and print it.
OUTPUT
Enter Admission number 1
Enter your Name a
enter your age34
admission no 1
Name a
age 34
2. Program to ask two number and print sum, subtract, divide and product.
a=float(input("enter first number "))
b=float(input("enter Second number "))
print("sum is ",a+b)
print("diff is ",a-b)
print("product is ",a*b)
print("divide is ",a/b)
3. Program to ask no of players participating in tournament (Basket Ball) from user and print no of
teams that can be formed and no of participant left.
n=int(input("enter no of players "))
team=n//5
left=n%5
print("No of Teams ",team)
print("no of players left ",left)
4. Write a Python program to convert temperature in degree Celsius to degree Fahrenheit. If water
boils at 100 degree C and freezes as 0 degree C, use the program to find out what is the boiling
point and freezing point of water on the Fahrenheit scale. (Hint: T(°F) = T(°C) × 9/5 + 32)
b_p_inC=100
f_p_inC=0
b_p_inF=b_p_inC*9/5+32
f_p_inF=f_p_inC*9/5+32
print("boiling point of water in C", b_p_inC)
print("boiling point of water in F", b_p_inF)
print("freezing point of water in C ", f_p_inC)
print("freezing point of water in F ", f_p_inF)
7. Program to ask three side of cuboid and print its perimeter and volume.
l=float(input("length"))
b=float(input("breadth"))
h=float(input("height"))
v=(l*b*h)
p=4*(l+b+h)
print("volume of cuboid",v)
print("perimeter of cuboid",p)
8. Program to calculate and print simple interest and Amount payable as Principal + SI
(SI=p*r*t/100).
p=float(input("enter principle amount "))
r=float(input("enter rate "))
t=int(input("enter time in years "))
si=p*r*t/100
print("simple insterest is ",si)
9. Program to perform the following:
Read the marks of three subjects: Computer Science, Mathematics, Physics out of 70
Calculate aggregate/total marks. Calculate percentage of marks. Print both of them.
c=float(input("enter marks of Computers(70) "))
p=float(input("enter marks of physics(70) "))
m=float(input("enter marks of maths (70) "))
total=c+p+m
per=total/210*100
print("Total marks (210) ",total)
print("Total percentage ",per)
10. Program to solve quadratic equation : ax2+ bx + c= 0 (d=b2-4ac) (r1=(-b+( d) /(2a)
11. Write a Python program to find the area of a rectangle.
12. Write a program to swap two numbers using a third variable.
13. Write a program to swap two numbers without using a third variable.
Decision control statement [ if (simple if) , if .. else, if .. elif .. else (Ladder if), nested if) ]
5. Program to ask ask from user and print eligible to vote or not
age=int(input("enter units consumed"))
if age>=18:
print("eligible to vote")
else:
print("Not eligible to vote")
6. Modify the above program such that it also print how many years user has to wait to vote.
age=int(input("enter units consumed"))
if age>=18:
print("eligible to vote")
else:
print("Not eligible to vote. Wait for ",18-age," years more for voting")
7. Program to ask a number from user and classify number as “Single Digit“, “Double Digit“ or “Big“.
N=int(input(“Enter The Number”))
if N<10:
print(N, “is single Digit Number”)
elif N<100:
print(N,”is double Digit Number”)
else:
print(N, “is Big Number”)
8. Program to ask a number and print no is zero, negative or positive.
N=int(input(“Enter The Number”))
if N<0:
print(N, “is Negative Number”)
elif N>0:
print(N,”is Positive Number”)
else:
print(N, “is Zero”)
9. Write an PROGRAM to display total Water Bill charges of the month depending upon the
number of units consumed by the customer as per following criteria:
(i) for the first 100 units @ 5 per unit
(ii) for next 150 units @ 10 per unit
(iii) more than 250 units @ 20 per unit
Also add meter charges of 75 per month to calculate total Water bill.
u=int(input("enter units consumed"))
if u<=100:
ch=u*5
elif u<=250:
ch= 100*5 + (u-100)*10
else:
ch = 100*5 + 150*10 + (u-250)*20
mc=75
print("Bill of consumption of units per month ",ch)
print("Meter charges per month ",mc)
print("total bill for ",u, " units with meter charges is ",ch+mc)
Strings :
13. WAP to ask a string and print no of words beginning with uppercase alphabet.
c=0
for i in n.split():
if i[0].isupper():
print(i)
c=c+1
print("Result is :",c)
14. WAP to ask a string and print no of words ending with lowercase alphabet.
c=0
for i in n.split():
if i[-1].islower():
print(i)
c=c+1
print("Result is :",c)
15. Wap to ask two strings and print found if first string contains second string otherwise print not
found.
b) 0,1,1,2,3,5,8,13,21,34….
c) 1,4,9,16,25,36,49,64,81,100…….
d) 1, 2, 4, 8, 16,32,64,128,256,612,1024
for a in range(1,11,1):
print(a)
a=1
while a<11:
Print(a)
a=a+1
s=0
n q=n//10 r=n%10 s=s+r s=s*10+r
156 15 6 0+66 0*10+66
15 1 5 6+511 6*10+565
1 0 1 11+112 65*10+1651
0
WAP to ask two numbers and print first number raise to power second number without using **
operator
print(c)
OR
a != b
15 T 40
15 T 40-15=25
15 T 25-15=10
5 T 10
5 F 10-5=5
WAP to ask two numbers and print LCM.
0 2 4 6 8
A=[1,4,2,7,9,12,43,45,63]
(i) Swap the even position elements with adjacent odd position elements
New A [4,1,7,2,12,9,45,43,63]
Output [4,2,7,9,12,43,45,63,1]
(ix) Shift last element of list as the first element in list as shown in example
Output [63,1,4,2,7,9,12,43,45]
(x) Program to remove all occurances of an element given by user from existing list
A=[2,4,6,2,5,4,2,4,2,6,7,2]
Val =2
Output : [4,6,5,4,4,6,7]
Revision: loop and if construct
1. Write a program that takes the name and age of the user as input and displays a message
whether the user is eligible to apply for a driving license or not. (the eligible age is 18 years)
Name=input(”Enter your name”)
Age=int(input(“Enter your age”))
if Age>=18:
print(“Eligible to get driving licencse”)
else:
print(“not Eligible to get driving licencse”)
2. Write a function to print the table of a given number.(Number has to be entered by the user.)
Num=int(input(“Enter number”))
for a in range(1,11):
print(a*Num)
3. Write a program to check if the year entered by the user is a leap year or not.
n=int(input("enter the year: "))
if n%100==0:
if n%400==0:
print("a century leap year ")
else:
print("not a century leap year")
else:
if n%4==0:
print(n," is a leap year")
else:
print(n," is not a leap year")
4. Write a program to generate the sequence: -5, 10,-15, 20 , -25….. upto n terms, where n is the
number input by the user.
n=int(input(“Enter the no. of terms required”))
for i in range(1,n+1):
Print(5*i*(-1)**I,end=” “)
5. Write a program to find the sum of 1+ 1/8 + 1/27......1/n3, where n is the number input by the
user.
n=int(input("enter the no. of terms required"))
c=0
for i in range(1,n+1):
if (i!=n):
print("1/",i**3,end="+")
else:
print("1/",i**3,end="")
c=c+1/i **3
print("\n",c)
6. Write a program to ask a number and print the sum of its digits.
(if n=180 then output must be 9.)
For I in range(1,5):
Print(“”)
For j in range(1,i):
Print(j,end=””)