0% found this document useful (0 votes)
3K views

Class XI Computer Science Holiday H

The document contains instructions for 21 Python programming assignments for students. The assignments include programs to calculate simple and compound interest, find factorials, check if a number is prime, display multiplication tables, find Fibonacci sequences, check if a number is Armstrong, find LCM and factors of numbers, count vowels in strings, print patterns, find numbers divisible by 7 and 5 in a range, reverse strings, count even and odd numbers, and find numbers where each digit is even. It also includes sample code solutions for some of the assignments.

Uploaded by

sofia gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views

Class XI Computer Science Holiday H

The document contains instructions for 21 Python programming assignments for students. The assignments include programs to calculate simple and compound interest, find factorials, check if a number is prime, display multiplication tables, find Fibonacci sequences, check if a number is Armstrong, find LCM and factors of numbers, count vowels in strings, print patterns, find numbers divisible by 7 and 5 in a range, reverse strings, count even and odd numbers, and find numbers where each digit is even. It also includes sample code solutions for some of the assignments.

Uploaded by

sofia gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Class XI Computer Science Holiday H.

W
1.Python Program to Calculate the Average of Numbers in a Given List

2.Python Program to Reverse a Given Number

3.Python Program to Take in the Marks of 5 Subjects and Display the Grade

4.Python Program to Read Two Numbers and Print Their Quotient and Remainder

5.Python Program to Accept Three Digits and Print all Possible Combinations from the Digits

6.Python Program to Print Odd Numbers Within a Given Range

7.Python Program to Find the Sum of Digits in a Number

8.Python Program to Find the Smallest Divisor of an Integer

9.Python Program to Count the Number of Digits in a Number

10.Python Program to Check if a Number is a Palindrome

11.Python Program to Read a Number n And Print the Series

"1+2+…..+n= "

12.Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
Solved programs
Write a lot of programs: interest calculation, primarily testing, and factorials.

1. Write a program to input principal amount, rate and time and calculate the simple interest and
amount after each of the year.

p= int(input( "ENTER PRINCIPAL AMOUNT : "))

r= int(input( "ENTER RATE : "))

t= int(input( "ENTER TIME : "))

for i in range (1,t+1):

interest= (p*r*i)/100

amount= p+ interest

print ("AFTER ",i, " YEAR ", " INTEREST = ",interest,

"AMOUNT = ",amount)

2. Write a program to input principal amount, rate and time and calculate the compound interest and
amount after each of the year.

p= int(input( "ENTER PRINCIPAL AMOUNT : "))

r= int(input( "ENTER RATE : "))

t= int(input( "ENTER TIME : "))

for i in range (1,t+1):

interest= (p*r*1)/100

p= p+ interest

print ("AFTER ",i, " YEAR ", " INTEREST = ",interest,

"AMOUNT = ",p)

3. Write a program to input a number and print the factorial of the number.

num= int(input( "ENTER NUMBER : "))

# check if the number is negative, positive or zero

if num < 0:
print("Sorry, factorial does not exist for negative numbers")

elif num == 0:

print("The factorial of 0 is 1")

else:

for i in range(1,num + 1):

factorial = factorial*i

print("The factorial of",num,"is",factorial)

4. Write a program to input a no and check whether prime or not.

Num = = int(input( "ENTER NUMBER : "))

if num > 1:

# check for factors

for i in range(2,num):

if (num % i) == 0:

print(num,"is not a prime number")

break

else:

print(num,"is a prime number")

# if input number is less than

# or equal to 1, it is not prime

else:

print(num," is not a prime number")

5. Write a program in python to display all the prime numbers within an interval .

lower = int( input(―enter lower range ―)

upper = int( input(―enter upper range ―)

print("Prime numbers between",lower,"and",upper,"are:")


for num in range(lower,upper + 1):

# prime numbers are greater than 1

if num > 1:

for i in range(2,num):

if (num % i) == 0:

break

else:

print(num)

6. Write a program in python to print the multiplication table of a no.

num = 12

# To take input from the user

num = int(input("Display multiplication table of? "))

# use for loop to iterate 10 times

for i in range(1, 11):

print(num,'x',i,'=',num*i)

7. Write a Program to display the Fibonacci sequence up to n-th term where n is provided by the user.

nterms = int(input("How many terms? "))

# first two terms

n1 = 0

n2 = 1

count = 0

# check if the number of terms is valid

if nterms <= 0:

print("Please enter a positive integer")

elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")

print(n1)

else:

print (n1,n2, end=‘ ‗)

print("Fibonacci sequence upto",nterms,":")

while count < nterms:

print(n1,end=' ')

nth = n1 + n2

n1 = n2

n2 = nth

count += 1

8. Write a program to input a no and check armstrong no or not

num = int(input(―Enter a number :‖))

sum=0

temp= num

while temp>0:

digit = temp % 10

sum += digit**3

temp //=10

if num == sum:

print (num, ―is Armstrong no‖)

else:

print (num, ―is not Armstrong no‖)

9. Write a Program to check Armstrong numbers in certain


interval.

# To take input from the user

lower = int(input("Enter lower range: "))

upper = int(input("Enter upper range: "))

for num in range(lower, upper + 1):

order = len(str(num))

sum = 0

# find the sum of the cube of each digit

temp = num

while temp > 0:

digit = temp % 10

sum += digit ** order

temp //= 10

if num == sum:

print(num)

10. Write a Python program to find the sum of natural

numbers up to n where n is provided by user

num = int(input("Enter a number: "))

if num < 0:

print("Enter a positive number")

else:

sum = 0

# use while loop to iterate un till zero

while(num > 0):

sum += num
num -= 1

print("The sum is",sum)

11. Write Python Program to find the L.C.M. of two inputted

number

x= int(input(―enter first no ―)

y= int(input(―enter second no ―)

if x > y:

greater = x

else:

greater = y

while(True):

if((greater % x == 0) and (greater % y == 0)):

lcm = greater

break

greater += 1

return lcm

12 Write Python Program to find the factors of a number x

x= int(input(―enter no ―)

print("The factors of",x,"are:")

for i in range(1, x + 1):

if x % i == 0:

print(i)

13. Write python Program to count the number of each vowel in a

string

vowels = 'aeiou'
ip_str = ip_str.casefold()

count = 0

# count the vowels

for char in ip_str:

if char in count:

count[char] += 1

print(count)

14. Write Python program to display output1

22

333

4444

55555

for i in range(1, 5):

for j in range(i):

print(i, end=' ')

print()

15. Write the python program to print the following

**

***

****

*****

n=6

for i in range(1,n):

for j in range(i):
print(j, end=‘ ‗)

print()

16. Write a Python program to find those numbers which are

divisible by 7 and multiple of 5, between 1500 and 2700 (both

included).

for x in range(1500, 2701):

if (x%7==0) and (x%5==0):

print (x)

17. Write a Python program to guess a number between 1 to 9.

import random

target_num, guess_num = random.randint(1, 10),0

while target_num != guess_num:

print target_num

guess_num = int(input('Guess a number between 1 and

10 until you get it right : '))

print('Well guessed!')

18. Write a Python program that accepts a word from the user and

reverse it.

word = input("Input a word to reverse: ")

for char in range(len(word) - 1, -1, -1):

print(word[char], end="")

print("\n")

19 Write a Python program to count the number of even and odd

numbers from a series of numbers 5 to 100.

count_odd = 0
count_even = 0

for x in range(1,101):

if not x % 2:

count_even+=1

else:

count_odd+=1

print("Number of even numbers :",count_even)

print("Number of odd numbers :",count_odd)

20. Write a Python program that accepts a string and calculate the

number of digits and letters.

s = input("Input a string")

d=l=0

for c in s:

if c.isdigit():

d=d+1

elif c.isalpha():

l=l+1

else:

pass

print("Letters", l)

print("Digits", d)

21 Write a Python program to find numbers between 100 and 400

(both included) where each digit of a number is an even number.

for i in range(100, 401):

s = str(i)
if (int(s[0])%2==0) and (int(s[1])%2==0) and (int(s[2])%2==0):

print( i))

You might also like