0% found this document useful (0 votes)
35 views37 pages

Ramjas International School Prgram File

The document is a practical file for Class 11 Computer Science students, containing various Python programming exercises. It includes tasks such as calculating gross salary, distance conversion, compound interest, and determining prime numbers, among others. Each question provides a brief description and the corresponding Python code to solve the problem.

Uploaded by

Aakansha Goyal
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)
35 views37 pages

Ramjas International School Prgram File

The document is a practical file for Class 11 Computer Science students, containing various Python programming exercises. It includes tasks such as calculating gross salary, distance conversion, compound interest, and determining prime numbers, among others. Each question provides a brief description and the corresponding Python code to solve the problem.

Uploaded by

Aakansha Goyal
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/ 37

RAMJAS INTERNATIONAL SCHOOL

R.K. PURAM SEC-4

PROGRAM FILE
PYTHON
Computer Science 083
Class: 11 Sec.: D
Roll No.: 30
Submit To : Submit By :
Mr. Gajendra Sharma Name: Ruchika Goyal
PGT Computer Science Class/Section: XI-D
Practical File Program Questions
Term 1

Q1 Write a program in python


to find gross salary. [gs= basic
+ da - pf + hra] int
1. bs = int(input("Enter Basic
Salary: "))
2. da = int(input("Enter
Dearness Allowance (DA): "))
3. pf = int(input("Enter
Provident Fund (PF): "))
4. hra = int(input("Enter
House Rent Allowance (HRA):
"))
5. gs = bs + da - pf + hra
6. print("The Gross Salary
is:", gs)
Q2 Write a program in python
calculate distance of 1056 feet in
terms of yards and miles. [1
mile=1760 yards, 1 yard = 3 feet]
float | int

1. FY = 3
2. YM = 1760
3. df= 1056
4. dy= df/FY
5. dm= dy/ YM
6. print(f"Distance in yards:
{dy:.2f} yards")
7. print(f"dm: {dm:.6f}
miles")
Q3 Write a program in python
calculate rounds of park if the
triangular park with sides as 30m,
25m and 35m and the athlete has
run 560m only.
1. a= 30
2. b=25
3. c=35
4. perimeter = a+b+c
5. print(“Perimeter of park
is:”, perimeter)
6. total_distance = 560 m
7. rounds_complete = total
distance//perimeter
8. print("The athlete can
complete
{int(rounds_complete)} full
rounds of the park.")

Q4 Write a program in python to take


principal, rate and time and display
compound interest [ci=p*(1+r/100) t]
[pow()] ci=p*pow((1+r/100),t)

a. p = float(input("Enter the
principal amount: "))

b. r = float(input("Enter the
rate of interest : "))
c. t = float(input("Enter the
time : "))
d. ci = p * pow((1 + r / 100),
t)
e. return ci

f. print("The Compound
Interest is:”, ci )

Q5 Write a program in python to


obtain x ,y and z from user and
calculate : 8x6+7y4+6z2+2π
[pow()]

2. x = float(input("Enter the
value of x: "))
3. y = float(input("Enter the
value of y: "))
4. z = float(input("Enter the
value of z: "))
5. R = 8 * pow(x, 6) + 7 *
pow(y, 4) + 6 * pow(z, 2) + 2 *
(22/7)
6. Print(The result is:”,R)

Q6 Write a program in python to find


n is even and odd
1. n = int(input("Enter a number:
"))
2. if n % 2 == 0:
3. return "Even"
4. else:
5. return "Odd"

Q7 Input marks of 3 subjects, write a


program to print result. If a student gets
40 & above in each subject then result is
“pass” else result is “fail”

1. s1 = int(input("Enter marks for


subject 1: "))
2. s2 = int(input("Enter marks for
subject 2: "))
3. s3 = int(input("Enter marks for
subject 3: "))
4. if s1>= 40 and s2 >= 40 and s3 >=
40:
5. return "Pass"
6. else:
7. return "Fail"

Q8 Write a program in python to check


whether a number is divisible 5 and 11.

1. n = int(input("Enter a number:
"))
2. d(n):
3. if n % 5 == 0 and n % 11 == 0:
4. return True
5. else:
6. return False
7. if d(n):
8. print("The number {n} is
divisible by both 5 and 11.")
9. else:
10. print("The number {n} is not
divisible by both 5 and 11.")

Q9 Write a program in python to find


which number is lowest in 4 numbers.

1. num1 = float(input("Enter the


first number: "))
2. num2 = float(input("Enter the
second number: "))
3. num3 = float(input("Enter the
third number: "))
4. num4 = float(input("Enter the
fourth number: "))
5. lowest = min(num1, num2, num3,
num4)
6. print(“Minimum number is:”,
lowest)
Q10 Write a program in python to assign a stream
to student according:
MARKS OBTAINED IN DIFF. SUBJECT
STREAM
English, maths and science >=80
pure science
English >=60, science and maths >=75
bio. Science
English, maths and science >=60
commerce
Others
humanity /art
1. english = int(input("Enter marks
in English: "))
2. maths = int(input("Enter marks
in Maths: "))
3. science = int(input("Enter marks
in Science: "))
4. stream(english, maths, science):
5. if english >= 80 and maths >= 80
and science >= 80:
6. return "Pure Science"
7. elif english >= 60 and maths >=
75 and science >= 75:
8. return "Bio Science"
9. elif english >= 60 and maths >=
60 and science >= 60:
10. return "Commerce" else:
11. return "No Stream Assigned"
12. print("The assigned stream is:”,
stream)

Q11 Write a program in python to print the


income, tax & surcharge of employ. The tax and
surcharge based on the following conditions
INCOME TAX RATE
SURCHARGE RATE
<₹15000 15%
7%
₹15001 to ₹20000 18%
11%
Above ₹20000 20%
13%
Total income= income- income/100*
tex rate - income/100* sr
1. income = float(input("Enter the
income: "))
2. tax_and_surcharge(income):
3. if income <= 15000: tax_rate = 0.15
surcharge_rate = 0.07
4. elif income <= 20000: tax_rate =
0.18 surcharge_rate = 0.11
5. else: tax_rate = 0.20 surcharge_rate
= 0.13
6. tax = income * tax_rate
7. surcharge = tax * surcharge_rate
8. print("Income:”, income)
9. print("Tax:”,tax)
10. print(f"Surcharge:”, surcharge)

Q12 Write a program in python to for


library charges a fine for books returned
late. Following are the fines :
DAYS FINE PER DAY
First five days (<=5) ₹.40
per day.
Six to ten day (6 to 10) ₹.65
per day.
Above ten days (10>) ₹.80
per day

1. delay= int(input("Enter the


number of days the book is returned
late: "))
2. fine(delay):
3. if delay <= 5:
a. fine = delay * 40
4. elif delay <= 10:
5. fine = (5 * 40) + ((delay - 5) *
65)
6. else:
7. fine = (5 * 40) + (5 * 65) +
((delay - 10) * 80)
8. return fine
9. print(“The total fine is: fine")

Q13 A cloth showroom has the


assured gifts on the purchase of
items, based on the total cost of the
item purchased :
TOTAL COST DISCOUNT
ASSURED GIFT
Less than or up to 2000 5%
wall clock
2001 to 5000 10%
school bag
5001 to 10,000 15%
electric iron
More than 10,000 20%
wrist watch
Write a program to input the total
cost of the item purchased, discount,
amount to be paid availing discount
and the assured gift.

1. Total_cost = float(input("Enter
the total cost of the item
purchased: ₹"))
2. details(total_cost):
3. if total_cost <= 2000:
4. discount_rate = 0.05
5. gift = "wall clock"
6. elif total_cost <= 5000:
7. discount_rate = 0.10
8. gift = "school bag"
9. elif total_cost <= 10000:
10. discount_rate = 0.15
11. gift = "electric iron"
12. else:
13. discount_rate = 0.20
14. gift = "wrist watch"
15. discount = total_cost *
discount_rate
16. amount_to_pay = total_cost -
discount
17. print(“Total cost: total_cost")
18. print("Discount: discount")
19. print("Amount to be paid after
discount: amount_to_pay”)
20. print("Assured gift: gift")

Q14 Write a program in python to calculate


area as follows :
1. Area of circle [a=πr2]
2. Area of squire [a=a*a]
3. Area of rectangle [a=l*b]
4. Area of triangle [a=
(b*h)/2]
import math

# Function to calculate the area of a circle

def area_of_circle(radius):

return math.pi * radius ** 2

# Function to calculate the area of a square

def area_of_square(side):

return side * side

# Function to calculate the area of a rectangle

def area_of_rectangle(length, breadth):

return length * breadth

# Function to calculate the area of a triangle

def area_of_triangle(base, height):

return (base * height) / 2

# Main function

def main():

print("Area Calculations")

# Area of Circle radius = float(input("Enter the radius of the circle: "))


circle_area = area_of_circle(radius)

print(f"Area of the circle: {circle_area:.2f}")

# Area of Square

side = float(input("Enter the side length of the square: "))

square_area = area_of_square(side)

print(f"Area of the square: {square_area:.2f}")

# Area of Rectangle

length = float(input("Enter the length of the rectangle: "))

breadth = float(input("Enter the breadth of the rectangle: "))

rectangle_area = area_of_rectangle(length, breadth)

print(f"Area of the rectangle: {rectangle_area:.2f}")

# Area of Triangle

base = float(input("Enter the base length of the triangle: "))

height = float(input("Enter the height of the triangle: "))

triangle_area = area_of_triangle(base, height)

print(f"Area of the triangle: {triangle_area:.2f}")

# Entry point of the program

if __name__ == "__main__":

main()
Q15 Write a Program to display all
prime numbers from n to m.

1. for num in range(n, m + 1):


2. if num > 1: # primes are
greater than 1
3. for i in range(2, num):
4. if (num % i) == 0:
5. break
6. else:
7. print(num)

8. # Example usage:
9. n = 10
10. m = 50
11. display_primes(n, m)
Q16 Write a program in python to
display 5th,9th ,13th and 17th Fibonacci
numbers

1. if n <= 0:
2. return "Input should be a positive
integer"
3. elif n == 1:
4. return 0
5. elif n == 2:
6. return 1
7. else:
8. a, b = 0, 1
9. for _ in range(2, n):
1. a, b = b, a + b
10. return b

# Display the 5th, 9th, 13th, and 17th


Fibonacci numbers
print("5th Fibonacci number:",
fibonacci(5))
print("9th Fibonacci number:",
fibonacci(9))
print("13th Fibonacci number:",
fibonacci(13))
print("17th Fibonacci number:",
fibonacci(17))
Q17 Write a program in python to
check given number is Armstrom or
not. Ex. 153 (cube and sum of all
digits)

def is_armstrong(number):

# Convert number to string to easily iterate through digits

digits = str(number)

power = len(digits) # Number of digits

sum_of_powers = sum(int(digit) ** power for digit in digits)

return sum_of_powers == number

def main():

# Input number from the user

num = int(input("Enter a number to check if it is an Armstrong number: "))

if is_armstrong(num):

print(f"{num} is an Armstrong number.")

else:

print(f"{num} is not an Armstrong number.")

# Entry point of the program

if __name__ == "__main__":
main()
Q18 Write a program in python to
check given number is unique
number or not. Ex. 1234,3451,6583
(no repeat)
def is_unique_number(number):

# Convert number to string to check each digit

digits = str(number)

# Use a set to track seen digits

seen = set()

for digit in digits:

if digit in seen:

return False # Digit is repeated

seen.add(digit)

return True # All digits are unique

def main():

# Input number from the user

num = int(input("Enter a number to check if it is a unique number: "))

if is_unique_number(num):

print(f"{num} is a unique number.")

else:

print(f"{num} is not a unique number.")

# Entry point of the program

if __name__ == "__main__":
main()
Q19 Write code for following:

a.)

1. for i in range(5, 0, -1):


2. print('5 ' * i)

b.)

1. for i in range(1, 6):


2. for j in range(i, 0, -1):
3. print(j, end=' ')
4. print()

c.)

1. num = 1
2. for i in range(1, 6, 2):
3. for j in range(i):
4. print(num, end=' ')
5. num += 1
6. print()

d.)

1. num = 1
2. for i in range(1, 5):
3. for j in range(i):
4. print(num, end=' ')
5. num += 1
6. print()
7. num -= 1
8. num -= i
Q20 Write a program to print
1.The first character of the string |
message
2.The last character of the string |
message
3.The first three characters of the
string | message
4.The last three characters of the
string | message

# Input from the user

message = input("Enter a string or message: ")

# 1. First character of the string

first_char = message[0]

# 2. Last character of the string

last_char = message[-1]

# 3. First three characters of the string

first_three_chars = message[:3]

# 4. Last three characters of the string

last_three_chars = message[-3:]
# Output the results

print("First character:", first_char)

print("Last character:", last_char)

print("First three characters:", first_three_chars)

print("Last three characters:", last_three_chars)


Q21 Write a program in python to count number
of words in message are start and end with
1. Upper letters
2. Lower letters
3. Digits
4. Special character
5. Vowel
6. Same character |user define
character | alphabet |letter
import string

# Input from the user

message = input("Enter a message: ")

words = message.split()

# Initialize counters

upper_start_end = 0

lower_start_end = 0

digit_start_end = 0

special_start_end = 0

vowel_start_end = 0

same_char_start_end = 0

# User-defined character for same start and end

user_char = input("Enter a character to check if words start and end with it: ").lower()

# Set of vowels

vowels = set("aeiouAEIOU")

special_chars = set(string.punctuation)
# Iterate through each word

for word in words:

first_char = word[0]

last_char = word[-1]

# Check for upper case start and end

if first_char.isupper() and last_char.isupper():

upper_start_end += 1

# Check for lower case start and end

if first_char.islower() and last_char.islower():

lower_start_end += 1

# Check for digit start and end

if first_char.isdigit() and last_char.isdigit():

digit_start_end += 1

# Check for special character start and end

if first_char in special_chars and last_char in special_chars:

special_start_end += 1

# Check for vowel start and end

if first_char in vowels and last_char in vowels:


vowel_start_end += 1

# Check for same character start and end

if first_char.lower() == user_char and last_char.lower() == user_char:

same_char_start_end += 1

# Output the results

print(f"Words that start and end with upper letters: {upper_start_end}")

print(f"Words that start and end with lower letters: {lower_start_end}")

print(f"Words that start and end with digits: {digit_start_end}")

print(f"Words that start and end with special characters: {special_start_end}")

print(f"Words that start and end with vowels: {vowel_start_end}")

print(f"Words that start and end with the character '{user_char}':


{same_char_start_end}")
Q22 Write a program in python that check the
character/word present in a string | message or
not.

# Input from the user

message = input("Enter a message: ")

# Ask the user if they want to search for a character or a word

search_item = input("Enter the character or word to search for: ")

# Check if the character or word is in the message

if search_item in message:

print(f"'{search_item}' is present in the message.")

else:

print(f"'{search_item}' is not present in the message.")


Q23 Write a program in python to input a
message and count the number of words
beginning with ‘a’ or ‘a’.

1. words = message.split()
2. count = 0
3. for word in words:
4. if word[0].lower() == 'a':
5. count += 1
6. return count

7. # Input a message from the user


8. message = input("Enter a message:
")

9. # Count and display the number of


words starting with 'a' or 'A'
10. a_word_count =
count_a_words(message)
11. print("Number of words starting
with 'a' or 'A':", a_word_count)
Q24 Write a program in python to take a
message from the user and display
longest word from message.
# Input from the user

message = input("Enter a message: ")

# Split the message into words

words = message.split()

# Find the longest word

longest_word = max(words, key=len)

# Output the result

print(f"The longest word is: '{longest_word}'")


Q25 Write a program in python to take 10
names and display number of consonants
and vowel of each name.
vowels = 'aeiou'
consonants = 'bcdfghjklmnpqrstvwxyz'
name = name.lower()
vowel_count = sum(1 for char in name if char in
vowels)
consonant_count = sum(1 for char in name if
char in consonants)
return vowel_count, consonant_count
# Input 10 names from the user
names = []
for i in range(10):
name = input(f"Enter name {i+1}: ")
names.append(name)

# Count and display the number of consonants and


vowels for each name
for i, name in enumerate(names):
vowel_count, consonant_count =
count_consonants_and_vowels(name)
print(f"Name {i+1}: {name}")
print(f" Vowels: {vowel_count}")
print(f" Consonants: {consonant_count}")
print()

Q26 Write a program in python to take 10


names and count name have equal length

1. name_lengths = [len(name) for name


in names]
2. max_length = max(name_lengths)
3. count = sum(1 for length in
name_lengths if length == max_length)
4. return count

5. # Input 10 names from the user


6. names = []
7. for i in range(10):
8. name = input(f"Enter name {i+1}: ")
9. names.append(name)

10. # Count and display the number of


names with equal length
11. equal_length_count =
count_equal_length_names(names)
12. print("Number of names with equal
length:", equal_length_count)

You might also like