Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Python Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

SUBJECT: COMPUTER SCIENCE(083)

ASSIGNMENT-DATA TYPES AND VARIABLES


Class : XI
Q1. Identify valid and invalid variable names from the following:-
percentage%, 12class, final-exam, Class, For, _subjects
Q2. Identify which of the following expressions are correct:
a) x,y,z=12.5, 170, 'Samarth'
b) x,y,z=12.5, 170, 'Samarth', k
c) x=y=z=100
d) x,y = 10,10, z = 10
e) x,y = 10

Q3. Give the data type of the following variables:


a) x= 'Raghav'
b) y= 100.56
c) z=10
d) t=15 +6j
e) var1=[120, 130, 140, 'Ajit']
f) var2=(‘May’, ‘June’, 5, 6)
g) num=true

Q 4. Determine the type of each of the following:


a) 42
b) 2
c) ‘42’
d) (4, 2)

Q5. Observe the following script and enlist all the tokens used in it.
#Identify tokens in the script
name="Fatima"
cl=eval(input("Enter class: "))
print (name,"studies in”, cl,"class")

Q6. Write a Python script to display the message “Python is interesting”.

Q7. Write a Python script to input two numbers and find their sum.

Q8. Write a Python script to input side of a square and display its area.

Q9. Write a Python script to input length and breadth of a rectangle and display its area and perimeter.

Q10. Write a Python script to input an integer and display its square and cube.

Q11. Write a Python script to input length in meters and convert it into centimeters.
SUBJECT: COMPUTER SCIENCE(083)
ASSIGNMENT-OPERATORS AND EXPRESSIONS
Class : XI
Q1. Write the corresponding Python expressions for the following mathematical expressions:
a) ex +(R +S)4
b) 2-4y *(P +Q)2-4y * (P +Q)2
c) A+B/(5AB)
d) ut+ 1/2ft2
e) v-w/(a+b)9

Q2. Evaluate the following expressions


a) 25-8**2/4 + 10
b) 25-8**2//4 + 10
c) 75%4+7-2**3+5
d) (8**2-3)%4+10
e) (8**2-3) % (4+10)

Q3. Evaluate the following expressions:


a) x-y<z and y+z >x or x-z<=y-x+z if x=4, y=8, z=9
b) y and (x-z) or not(2y<z-x) if x=10 ,y=11, z=10
c) not(a<b) and c<> d or b+c < a where a=7, b=3, c=5, d=6

Q4. Evaluate the following expressions:


a) x *(y**2) –y % 10 +3
b) (x+y > z) and ( x – y = = - z + y)
c) (x<y) and (z==x) || y
d) (x>=y) or (not(z)==y) and (z<x) where x=8, y=10, z=8

Q5. Write a Python script to input a three digits number and find the sum of its digits.

Q6. Write a Python script to input a temperature in Celsius and convert it into Fahrenheit.

Q7. Write a Python script to input the values of a,b,c and calculate the roots of the quadratic equation.

Q8. Write a Python script to input sides of a triangle and calculate its area.

Q9. Write a Python script to input the values of Principal, Rate, and Time and calculate Simple Interest and
Compound Interest.
Q10. Write a Python script to input time in seconds and display the number of hours, minutes and seconds in
the given seconds.
SUBJECT: COMPUTER SCIENCE(083)
ASSIGNMENT- SELECTION STATEMENT

Class : XI
IF STATEMENTS
1) Write a program to input a year in 4-digit form and check whether it is a leap year or not and display
proper message.

2) Write a program to input a character. If it is lowercase letter, convert it to uppercase and vice versa.
3) Write a program to input co-efficients of a, b and c of a quadratic equation ax2 + bx + c = 0, where
Discriminant, D = b2- 4ac.If discriminant is 0 then print there is exactly one real root, if discriminant is
positive then print there are two distinct roots, if discriminant is negative then print then there are no real
roots. Also calculate and display the roots of the quadratic equation.

4) Write a program to calculate commission for the salesman. The commission is calculated as follows:
Sales Commission Rate
30001 onwards 15%
22001 - 30000 10%
12001 – 22000 7%
5001 – 12000 3%
0 - 5000 0%
5) Write program to input a character and check whether it is a vowel or not and display proper message.
6) Write a program to input two numbers and check whether both are divisible by 5.

7) Write a program to input the name, subject, salary and experience (in years) of a teacher. An allowance is
given according to the following condition:
If salary >10,000 and experience > 10 years, allowance is 20% of salary.
If salary is in the range 5000-10000 and experience >5years, allowance is 15% of salary. Otherwise if
salary >3000, allowance is 10%.
Otherwise if salary <3000, allowance is 6%.
Find the total salary (salary+allowance) and print it along with other details.

8) OUTPUT QUESTIONS

a) a=3
a=a+1
if a>5:
print(a)
else:
print(a+5)
b) NoOfGirls = 4
NoOfBoys = 10
if NoOfBoys == 8 and NoOfGirls <= NoOfBoys :
print("Great achievement")
else:
print("Greater achievement")

c) circle=5
rectangle=0
square=4
triangle = 0
if circle:
if rectangle or square:
print("Draw diagram")
elif not rectangle and not square:
print("Invalid diagram");
else:
if circle == rectangle or square == triangle:
print("Canvas Available")
print("Invisible diagram")

d) ch=3
if ch = = 1:
print(“ Laptop”)
elif ch = = 2:
print(“Desktop ”)
elif ch= = 3:
print (“Notebook”)
else:
print(“Invalid Choice”)
SUBJECT: COMPUTER SCIENCE(083)
ASSIGNMENT-ITERATIVE STATEMENTS
Class : XI
1) Write a program to accept an integer and check whether it is a prime number or not and display proper
messages.
2) Write a program to accept an integer and check whether it is palindrome or not and display proper messages.
3) Write a program to accept an integer and check whether it is an Armstrong number or not and display proper
messages.
4) Write a program to accept two integers and find the LCM and GCD of these numbers and display it.
5) Write a program to accept an integer and find the sum of digits of that number and display it
6) Write a program to accept an integer and generate the divisors of that integer. Eg: If the number is 6 then its
divisors are 1 2 3 6
7) Write a program to accept the number of terms of the Fibonacci series and print the series till that term. ie.,0 1
1 2 3 5 8 …………………………………………
8) Write a program to print the sum of the following series. Accept the value for ‘x’ and the number of terms of
the series. 1 – x2 + x4 – x6 + .......................... xn
9) Write a program to accept the number of lines and print the following pattern. Eg: If the number of lines is 4,
then the pattern should be as follows. 1 1 2 1 2 3 1 2 3 4
10) Write a program to accept an integer and print the multiplication table of that number till 10 in the following
format. Eg: if number is 5
5x1=5
5 x 2 = 10
5 x 3 = 15
11) Write a program to accept the number of lines and print the following pattern. Eg: If the number of lines is 3,
then the pattern should be as follows.
A
AB
ABC
12) Write a program to accept an integer and display the factorial of that number. Eg: if the number is 3 then 3! is
6.
13) Write a program to accept an integer and display the reversed integer (store the reversed number in a
variable). Eg: If the number is 267 then the reversed number is 762
14) Write a program to print the sum of negative numbers, sum of positive even numbers, sum of positive odd
numbers from a list of numbers entered by the user. The list terminates when the num entered is zero.
15) Write a program to sum the given series. Accept the number of terms from the user. 2 - 5 + 8 .................................. 9
13 17
16) Write a program to accept the number of lines and print the following pattern. Eg: If the number of lines is 4,
then the pattern should be as follows.
*
**
***
****
17) Write a program to input n and print first ‘n’ odd numbers in descending order. Eg: if number is 10, then the
output is 9 7 5 3 1
18) Write a program to accept the number of lines and print the following pattern. Eg: If the number of lines is 3,
then the pattern should be as follows.
1
121
12321

19) Write a program to print all prime numbers from 1 to ‘n’. Accept the value for ‘n’ from the user. Eg: If number
is 10, then the output is 2 3 5 7
20) Write a program to accept an integer ‘n’ (2 digit or more) and form a new integer that has the number of digit
in ‘n’ at the ten’s place and the most significant digit of ‘n’ at the one’s place. Eg: If the number is 458 then the
new number is 343

OUTPUT QUESTIONS
a) for I in range(20,100,10): k=k+1
j=I/2 print(k)
print(j)
for I in range(1,10,2): d) for i in [0,1,2]:
j=I/2 print(i*5)
print(j) else:
print(i*10)
b) for I in range(0,10,1):
if(I%2==0): e) i=10
print(I) while i<=100:
i=i+10
c) k=10 if(i%4==0):
while k>10: continue
print(k) print(i)

CONVERSION QUESTIONS
Convert the following code segment into while loop.
for I in range(1,20,1):
print(I)

Convert following while loop to for loop


x=0
while(x<=100):

print(” the value of x is \n”,x)


print(”done \n”)
x=x+20
SUBJECT: COMPUTER SCIENCE(083)
ASSIGNMENT- PYTHON STRINGS
Class : XI
Q1 Give the output:
a) print('''Rajan said, "It’ a lovely day"''')
b) print("Ram said, \"I AM LEARNING PYTHON")
c) print("Ram said, "I AM LEARNING PYTHON"")
d) print ('Sangeeta said, "I’ve got good grades" ')
e) print ('Sangeeta said, "I\’ve got good grades" ')
f) print("A goal \n without a plan is just a \t wish")

Q2 Give the elements of the following string which are present at the given index numbers:
str="Hard work pays off"
str [2]
str [-3]
str [2:5]
str [2:5:2]
str [:5]
str [3:]
str [::2]
str [::-2]
str [-5:-2]
str [5:2:-1]
str [-2:-5:-1]
str [-2:-5:-2]

Q3. Consider the following strings:


str1="Dreams don’t work unless you do"
str2="Hard work pays off"
Identify which of the following operation is possible on strings. If possible, write Python statements for the
following:

a) To add “Thanks” at the end of the string str1.


b) To add string str2 at the end of the string str1.
c) To replace the word “unless” in the string str1 with “if”.
d) To insert the word “Thanks” after the word “Dreams” in string str1.
e) To remove the third character from the string str1.
f) To delete the entire string str1.
g) To traverse the string str1 using for loop.
h) To traverse the string str2 using while loop.
Q4. Consider the strings str1 and str2 and give the output of the following Python statements:
str1="Dreams don’t work unless you do"
str2="Hard work pays off"
a) str2=str1+str2
b) str1=str2+str1
c) str2=str*2
d) "work" in str1
e) "off" not in str2
f) print (r 'Please \n note this')

Q5. Give the output of the following Python statements:


str1="Information age #2018"
str="@"

a) len(str1)
b) print(str1.capitalize())
c) print(str1.isalnum())
d) print(str1.isalpha())
e) print(str1.isdigit())
f) print(str1.lower())
g) print(str1.upper())
h) print(str1.islower())
i) find('In')
j) find('a')
k) find('a', 8)
l) find('in')
m) print (str1.isspace())
n) print(str1.isupper())
o) istitle()
p) join(str1)
q) print(str1.replace('a', '@'))
r) partition('age')
s) split('e')

Q5. Write Python script to input a string and a character and count the number of occurrences of the character
in the string.

Q6. Write Python script to input a string and display it in reverse order.

Q7. Write Python script to input a string and check whether it is a palindrome or not.
Q8. Write Python script to input a string and count the number of words in it.

Q9. Write Python script to input a string and count the number of words beginning with ‘A; or ‘a’.
Q10. Write Python script to input a string and replace the first letter of every word to uppercase and then
display it.
Q11. Write Python script to input a string and replace all occurrences of the word ‘the’ with ‘that’.
Q12. Write Python script to input a string and count and display the number of capital alphabets, small
alphabets and numbers.
SUBJECT: COMPUTER SCIENCE(083)
ASSIGNMENT- PYTHON TUPLES
Class : XI
Q1. Find the incorrect statement/s out of the following:

a) >>> tup1=(1,'2',3,4,5,"6",7,8,9)
b) >>>tup4=(170,)
c) >>>tup6= (500)
d) >>>tup7=tuple()
e) >>>tup10=5, 10, 15, 20

Q2 If
>>>tup1=("bag", "book", "copy", "lunch box", "pencil box")
>>>tup2=(5, 10, 15, 20, 25, 30, 35)

Give the output:


a) >>>tup3= tup1[:]
b) >>>tup4= tup2[1:5]

Q3 Give the elements of the following tuple which are present at the given index numbers:
planets=['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']

a) planets [5]
b) planets [2*2]
c) planets [-4]
d) planets [2:6]
e) planets [2:6:2]
f) planets [:4]
g) planets [2:]
h) planets [::2]
i) planets [::-2]
j) planets [-5:-1]
k) planets [5:2:-2]
l) planets [-2:-5:-1]
m) planets [-1:-5:-2]

Q4. Consider the following tuple:


monuments=[ 'Kutub Minar', 10, 'Taj Mahal', 20, 'India Gate', 30, 'Char Minar', 40]
states=['Delhi', 'Kerala', 'Tamil Nadu', 'Bihar']
Write Python statements for the following. Kindly state the reason for the operations which not possible.

a) To insert “Red Fort” and “Jantar Mantar” in the tuple monuments


b) To add 50 at the end of the tuple
c) To add tuple of states at the end of the tuple of monuments
d) To replace 3rd, 4th and 5th element of the monuments tuple by “India”.
e) To remove the third element from the tuple monuments.
f) To delete the tuple monuments.
g) To store all elements 2 times in the tuple states.
h) To check whether the element 20 is present in the tuple or not.
i) To swap the elements of tuples, monuments and states.
j) To display all elements of a tuple states in different lines.

Q5 Consider the tuples planets and states and give the output of the following Python statements:

planets=['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']


states=['Delhi', 'Kerala', 'Tamil Nadu', 'Bihar', 'Delhi']
a) planets=planets+”Tamil”
b) states=states*2
c) len(planets)
d) max(planets)
e) min(planets)
f) count(‘Delhi’)
Q6. Write Python script to display the element with maximum value from the given tuple.

Q7. Write Python script to display the element with minimum value from the given tuple.

Q8. Write Python script to display the sum of elements from the given tuple of numbers.

Q9. Write Python script to display the average of elements from the given tuple of numbers.

Q10. Write a Python script to input a tuple with names of dance forms. Input a dance form and add this dance
form at end of the touple.
SUBJECT: COMPUTER SCIENCE(083)
ASSIGNMENT- PYTHON DICTIONARY
Class : XI
Q1. Find the incorrect statement/s out of the following:

a) >>> dict1={'A': 'Apple', 'B':'Boy', 'C':'Cat', 'D':'Dog'}


b) >>>print(dict1[‘a’] )
c) >>> print(dict1[‘B’] )
d) >>> print(dict1[‘Cat’] )
e) >>> print(dict1[‘E’] )

Q2. Consider the following dictionary:


states=['D':'Delhi', 'K':'Kerala', 'T':'Tamil Nadu', 'B':'Bihar']
Write Python statements for the following. Kindly state the reason for the operations which not possible.

a) To insert (‘R’:“Red Fort”) and (‘J’:“Jantar Mantar”) in the dictionary states


b) To replace the value of key ‘K’ by ‘Karnataka’.
c) To remove the element with key ‘B’.
d) To delete the dictionary, states.
e) To return a sorted list of keys in the dictionary, states
f) To check whether the element with key ‘D’ is present in the dictionary or not.
g) To display all elements of a dictionary states in different lines.

Q3 Consider the dictionary dict3 and dict4 and give the output of the following Python statements:

dict2={10:'Hockey', 20:'Cricket', 30: 'Basket Ball', 40: 'Volley Ball' }


dict3={10:100, 50:500, 60:600}
a) items() d) get(10,’NA’) g) print(dict2)
b) key() e) get(80, “NA”) h) print(dict3)
c) values() f) update(dict3)

Q4. Write Python script to input class and the name of the class teacher and delete a particular class and its
teacher name.
Q5. Write Python script to create a dictionary with country name and its capital and also display it.

Q6. Write Python script to create a dictionary with country name and its population and also display it. Input
another country and its population and add it the existing dictionary.

Q7. Write Python script to create a dictionary with famous monuments and their location. Input name of any
monument and check whether that monument is present in the dictionary or not.
SUBJECT: COMPUTER SCIENCE(083)
ASSIGNMENT- PYTHON LISTS
Class : XI
Q1 Give the output:
a) >>>list1= ["Kathak", "Kathakali", "Odissi", "Manipuri", "Kuchipudi"]
b) >>>list2=[100, 200, 300, 400, 500,600]
c) >>>list3= list1[:]
d) >>>list4= list2[2:5]
Q2 Give the elements of the following list which are present at the given index numbers:

languages=['Hindi', 'English', 'Bengali', 'Oriya', 'Telugu', 'Marathi', 'Malayalam']

a) languages [2]
b) languages [-3]
c) languages [2:5]
d) languages [2:5:2]
e) languages [:5]
f) languages [3:]
g) languages [::2]
h) languages [::-2]
i) languages [-5:-2]
j) languages [5:2:-1]
k) languages [-2:-5:-1]
l) languages [-2:-5:-2]

Q3. Consider the following list:

monuments=[ 'Kutub Minar', 10, 'Taj Mahal', 20, 'India Gate', 30, 'Char Minar', 40]

states=['Delhi', 'Kerala', 'Tamil Nadu', 'Bihar']

Write Python statements for the following:

a) To insert “Red Fort” at index number 5


b) To add 50 at the end of the list
c) To add list states at the end of the list monuments
d) To replace 3rd, 4th and 5th element of the monuments list by “India”.
e) To remove the third element from the list monuments.
f) To delete 3rd to 5th elements from the list monuments.
g) To display the index number of the element “Kerala” from the states list.
h) To check whether the element 20 is present in the list or not.
Q4. Consider the lists languages and states and give the output of the following Python statements:

languages=['Hindi', 'English', 'Bengali', 'Oriya', 'Telugu', 'Marathi', 'Malayalam']


states=['Delhi', 'Kerala', 'Tamil Nadu', 'Bihar', 'Delhi']

a) languages=languages + ”Tamil”
b) states=states*2
c) len(languages)
d) max(languages)
e) min(languages)
f) count(‘Delhi’)

Q5. Write Python script to display the element with maximum value from the given list.

Q6. Write Python script to display the element with minimum value from the given list.

Q7. Write Python script to display the sum of elements from the given list of numbers.

Q8. Write Python script to display the average of elements from the given list of numbers.

Q9. Writ a Python script to input a list of numbers and a number. Check whether the given number is present
in the list or not.

Q10. Write a Python script to input a list and find all duplicates and display number of times they are present
in the list.

You might also like