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

Xi Assignment Beginning With Python Programing 04082024 222527

Hhh

Uploaded by

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

Xi Assignment Beginning With Python Programing 04082024 222527

Hhh

Uploaded by

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

Beginning with Python Programing

1. Which of the following identifier names are invalid and why?

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+15
num1 = 2 2
print (num1, num2)
2 5

4. num1, num2 = 2, 6
num1, num2 = num2, num1 + 2 num16 num28
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

x. print('Bye'== 'BYE') => False


xi. print(10 != 9 and 20 >= 20) True
xii. print(10 + 6 * 2 ** 2 != 9//4 -3 and 29 >= 29/9) =>True

34 > 56 or 90 > 60 and not 21>10


False or True and not True
False or True and False
False or False

Simple Python Programs:

1. Program to ask admission number, name and age from user and print it.

ano=int(input("Enter Admission number "))


name=input("Enter your Name ")
age=int(input("enter your age"))
print("admission no ",ano)
print("Name ",name)
print("age ",age)

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)

5. Program to calculate volume of cylinder. (3.14*r2*h)

r=float(input("enter radius "))


h=float(input("enter height"))
vol=3.14*r*r*h
print("volume is ",vol)

6. Program to find area and circumference of circle.


r=float(input("enter the radius of the circle"))
c=2*3.14*r
a=3.14*r*r
print("circumference of the circle",c)
print("area of the circle",a)

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) ]

1. Program to ask two number and print maximum among them.


a=float(input("enter first number"))
b=float(input("enter Second number"))
if a>b:
print(a, "is max")
elif b>a:
print(b," is max")
else:
print (a," is equal to ",b)
2. Program to ask three number and print maximum among them.
a=float(input("enter first number"))
b=float(input("enter Second number"))
c=float(input("enter Third number"))
if a>=b and a>=c: max=a if a>b:
print(a, "is max") if b>max: if a>c:
elif b>=a and b>=c: max=b print(a,” is max”)
print(b," is max") if c>max: else:
else: max =c print(c, “is max”)
print (c," is max ") print(max, “is max”) else:
if b>c:
print(b,” is max”)
else:
print(c, “ is max”)
3. Program to ask a number and print even or odd.
N=int(input(“enter the no to check”))
if N%2==0:
Print(N, “is even”)
else:
Print(N , “ is Odd”)
4. Write a Program that performs the following: Ask a user to enter a number. If the number is
between 5 and 15, write the word GREEN. If the number is between 15 and 25, write the word
BLUE. if the number is between 25 and 35, write the word ORANGE. If it is any other number,
write that ALL COLOURS ARE BEAUTIFUL.
n=int(input("enter the number "))
if n>=5 and n<15 :
print("Green")
elif n>=15 and n<25 :
print("blue")
elif n>=25 and n<35 :
print("orange")
else :
print("all colurs are beautifull")

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 :

N=input(“enter the string “) RAM


for i in N: i R
print(i,end=” “) i A
i M

for i in range(0,len(N)): i 0 N[i] R


print(N*i+, end=” “) i 1 N[i] A
i 2 N[i] M
1. WAP to ask a string and print no of vowels it contain.
N=input("enter the string ")
c=0
for i in N:
print(i,end=" ")
if i in "AEIOUaeiou":
c=c+1
print("no of vowels are ",c)

2. WAP to ask a string and print no of consonants it contain.


N=input("enter the string ")
c=0
for i in N:
print(i,end=" ")
if i.isalpha():
if i not in "AEIOUaeiou":
c=c+1
print("no of consonants are ",c)

3. WAP to ask a string and print no of alphabets it contain.


N=input("enter the string ")
c=0
for i in N:
print(i,end="")
if i.isalpha():
c=c+1
print("no of alphabets are ",c)

4. WAP to ask a string and print no of uppercase alphabet it contain.

N=input("enter the string ")


c=0
for i in N:
print(i,end="")
if i.isupper():
c=c+1
print("no of uppercase alphabets are ",c)
5. WAP to ask a string and print no of lower alphabet it contain.

N=input("enter the string ")


c=0
for i in N:
print(i,end="")
if i.islower():
c=c+1
print("result is ",c)

6. WAP to ask a string and print no of spaces it contain.

N=input("enter the string ")


c=0
for i in N:
print(i,end="")
if i.isspace():
c=c+1
print("no of spaces are ",c)

7. WAP to ask a string and print no of special character it contain.


N=input("enter the string ")
c=0
for i in N:
print(i,end="")
if not (i.isalnum() or i.isspace()):
c=c+1
print("\n no of Spl . characters are ",c)
8. WAP to ask a string and print no of digits it contain.

N=input("enter the string ")


c=0
for i in N:
print(i,end="")
if i.isdigit() :
c=c+1
print("\n result is ",c)

9. WAP to ask a string and print no of words it contain.

n=input("enter the string")


c=0
for i in n.split():
c=c+1
print("no of words are :",c)

10. WAP to ask a string and print no of words of length 4 it contain.


n=input("enter the string")
c=0
for i in n.split():
if len(i)==4:
print(i)
c=c+1
print("no of words with length 4 are :",c)
11. WAP to ask a string and print no of words beginning with vowels.
n=input("enter the string")
c=0
for i in n.split():
if i[0] in "AEIOUaeiou":
print(i)
c=c+1
print("no of words beginning with vowels are :",c)
12. WAP to ask a string and print no of words ending with vowels it contain.

n=input("enter the string")


c=0
for i in n.split():
if i[-1] in "AEIOUaeiou":
print(i)
c=c+1
print("no of words beginning with vowels are :",c)

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.

n=input("enter the string ")


a=input("enter the search string ")
c=n.find(a)
if c==-1:
print("search string not found in main string")
else:
print("search string found at ",c)
16. WAP to ask a string and a character to search and delete from the given string.
n=input("enter the string ")
a=input("enter the character to remove/delete from main string : ")
c=n.replace(a,””)
print(c)
or
c=n.count(a)
newstr=""
for i in n:
if I != a:
newstr=newstr+i
print("newstring after removal of character ",a,"is ",newstr)

17. WAP to ask a string print palindrome or not.

N=input(“enter the string to check for palindrome “


if N==N[::-1]:
print(N,“ is Palindrome”)
else:
print(N,” is Not palindrome)
(Words which remain same after reverse eg RADAR)

Loop (Iterative Statement)

# program to print first 10 natural number


Practice Questions :
1. WAP To print first 10 even numbers
for i in range(2,21,2):
print(i, end=" ")

2. WAP to print first 10 odd numbers.


for i in range(1,20,2):
print(i, end=" ")

3. WAP to print first N even Numbers.


n=int(input("enter no of even number required : "))
for i in range(2,2*n+1 ,2):
print(i, end=" ")

4. WAP to print first N odd Numbers.


n=int(input("enter no of ODD numbers required : "))
for i in range(1,2*n ,2):
print(i, end=" ")

5. WAP to print first N even Numbers in reverse order.


n=int(input("enter the number of terms of even numbers required :"))
for i in range(2*n,1,-2):
print(i,end=" ")
6. Print the given series :
a) 1,4,7,10… 40
For I in range(1,41,3):
Print(I)

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

7. WAP to print first N odd Numbers in reverse order.


n=int(input("enter the number of terms of odd numbers required :"))
for i in range(2*n-1,0,-2):
print(i,end=" ")
8. WAP to print first N natural Numbers.
9. WAP to print first N natural Numbers in reverse order.
10. WAP to print sum of first N natural Numbers.
n=int(input("enter the number of terms to be summed : "))
sum=0
for i in range(1,n+1):
sum=sum+i
print(sum)
11. WAP to ask a Number and print its table.
n=int(input("enter the number of which table is required : "))
for i in range(1,11):
print(n*i,end=” “) # print(n,"*",i,"=",n*i)

12. WAP to ask a Number and print its factorial.


5! = 5*4*3*2*1 or 1*2*3*4*5 or 5*4*3*2 or 2*3*4*5
n=int(input("Enter the no. to find Factorial "))
fact=1
for i in range (n,1,-1):
fact=fact*i
print("Factorial of ",n," is ",fact)

13. WAP to print sum of first N natural numbers.


n i rem output c=0=>c=c+1 c=0 => c=c+i
6 % 1 0 1 0+1  1 0+1 1
6 % 2 0 2 1+1  2 1+2 3
6% 3  0 3 2+1  3 3+3 6
6% 4 2 3 6
6% 5 1 3 6
6% 6 0 6 3+1 4 6+612
14. WAP to ask a Number and print number of factors it has.
N=int(input(“Enter the no. “))
c=0
for i in range(1,N+1):
if N%i ==0:
print(i,end=” “)
c=c+1
print(“no of factors are “,c)
if c==2:
print(n,”is prime”)
else:
print(n,“not prime”)

15. WAP to ask a number and print prime or not


if c==2:
print(n,”is prime”)
else:
print(n,“not prime”)

16. WAP to ask number and print it is perfect number or not


6 = 1+2+3+6 = 12
N=int(input(“Enter the no. “))
c=0
for i in range(1,N+1):
if N%i ==0:
print(i,end=” “)
c=c+1
print(“no of factors are “,c)
if c==2*N:
print(n,”is perfect number”)
else:
print(n,“not perfect number”)
17. WAP to ask a Number and print it is a perfect square of not 9 16 25 18
N SR = N**.5 SR*SR==N
25 5
16 4
n=int(input("enter the number"))
sr=n**.5
if sr*sr==n:
print(n,"Perfect square of ", sr)
else:
print(n," is not perfect square")
18. WAP to print N terms of Fibonacci series.
n=int(input("Enter the No of terms required of Fibonacci series"))
if n>2:
a=0
b=1
print(a, " ",b,end=" ")
for i in range(2,n):
c=a+b
print(c,end=" ")
a=b
b=c
else:
print("minimum terms must be atleast 3")

Predict the output :

(i) for a in range (1,20):


if a%2==0:
print(a,sep=” “)
2 4 6 8 10 12 14 16 18
(ii) n=18
for a in range(1,n+1):
if n%a==0:
if a%2==0:
print(a,sep= “ “)
2 6 18

Find the sum of series :

a) x/2+ x2/3 + x3/4…..N terms


b) x/1 + x2/2 + x3/3 …. N terms
c) x/1 + x3/2 + x5/3 …. N terms
While LOOP Questions

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+66 0*10+66
15 1 5 6+511 6*10+565
1 0 1 11+112 65*10+1651
0

N=int(input(“enter the Number”))


S=1 for product or 0 sum
while(N>0):
q=N//10
r=N%10
N=q
s=s*r  s=s+r  s=s+1  s=s*10+r s=s+r**3
Print(s)
 WAP to ask a number and print sum of its digit eg 134 output 8
 WAP to ask a number and print product its digit eg 134 output 12
 WAP to ask a number and print number digits it contain. eg 134 output 3
 WAP to ask a number and print reverse of the number wg 132 output 231
 WAP to ask a number and print sum of cube of digits eg 132 output 1+27+8=36
 WAP to ask a number and print armstrong number or not.

N=int(input(“enter the Number”))


S=0
while(N>0):
q=N//10
r=N%10
N=q
s=s+r**3
print(s)
if s==cn:
print(cn,” is Armstrong Number”)
else:
print(cn,” is not Armstrong Number”)
 WAP to ask a number and print palindrome number or not

N=int(input(“enter the Number”))


S=0
while(N>0):
q=N//10
r=N%10
N=q
s=s*10+r
print(s)
if s==cn:
print(cn,” is Palindrome Number”)
else:
print(cn,” is not Palindrome Number”)

 WAP to ask two numbers and print first number raise to power second number without using **
operator

a=int(input("Enter First Number"))


b=int(input("Enter Second Number"))
c=1
for i in range(1,b+1):
c=c*a

print(c)

 WAP to ask two numbers and print HCF.


A b r=a%b
40 15 10
15 10 5
10 5 0

a=int(input("Enter the first number"))


b=int(input("Enter the Second number"))
r=a%b
while(r!=0):
r=a%b
if (r==0):
print("hcf is ",b)
a=b
b=r

OR

a=int(input("Enter the first number"))


b=int(input("Enter the Second number"))
while(a!=b):
if a>b:
a=a-b
else:
b=b-a
print(a)

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.

a=int(input("Enter the first number"))


b=int(input("Enter the Second number"))
ca=a
cb=b
while(a!=b):
if a>b:
a=a-b
else:
b=b-a
print("HCF is ",a)
print("LCM is ",(ca*cb)/a)

 WAP to add two numbers given by user without using + operator.


C=A-(-B)
 WAP to print first n terms of Fibonacci series . 0,1,1,2,3,5,8,13,21,34……
List Manipulation:

Consider the following List :

0 2 4 6 8

A=[1,4,2,7,9,12,43,45,63]

Write Function to achieve the following output :

(i) Swap the even position elements with adjacent odd position elements
New A [4,1,7,2,12,9,45,43,63]

(ii) Swap first half elements with second half


New A [12,43,45,63,9, 1,4,2,7]
(iii) Reverse the list
New A [63,45,43,12,9,7,2,4,1]
(iv) Print sum of even elements of the list
Output  18
(v) Print all odd elements and also their count.
Output1 7 9 43 45 63 count6
(vi) Add 5 to all even elements and subtract 1 from all odd elements
Output0 9 7 6 8 17 42 44 62
(vii) Shift first element to last of list as shown in example

Output  [4,2,7,9,12,43,45,63,1]

(viii) Shift first n element from starting to last as shown in example


A=[1,4,2,7,9,12,43,45,63]

If n=2 then Output  [2,7,9,12,43,45,63,1,4]

(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.)

7. Print the patten


(i) 1 (ii) 1 2 3 4 (iii) 1 1 1 1 (iv) 4444
12 123 222 333
123 12 33 22
1234 1 4 1
8. Write a program to ask a string and print no. of words it contain.
9. Write a program to ask a string and a character. The program should print print no. of occurances of
the character given by user, present in the string.
10. program to ask a sentence and print all words beginning with vowels . Also print no of words present
in sentence beginning with vowels.

For I in range(1,5):
Print(“”)
For j in range(1,i):
Print(j,end=””)

You might also like