Python Assignment
Python Assignment
Python Assignment
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")
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
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)
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]
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)
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]
Q5 Consider the tuples planets and states and give the output of the following Python statements:
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:
Q3 Consider the dictionary dict3 and dict4 and give the output of the following Python statements:
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:
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]
monuments=[ 'Kutub Minar', 10, 'Taj Mahal', 20, 'India Gate', 30, 'Char Minar', 40]
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.