0% found this document useful (0 votes)
8 views14 pages

Sachiv Project

The document provides a series of programming exercises using Python, covering various topics such as printing personal information, mathematical calculations, list manipulations, and conditional statements. Each exercise includes a question, an answer with code snippets, and expected outputs. The exercises are designed to help users practice basic programming concepts and syntax in Python.

Uploaded by

yorainbow28
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)
8 views14 pages

Sachiv Project

The document provides a series of programming exercises using Python, covering various topics such as printing personal information, mathematical calculations, list manipulations, and conditional statements. Each exercise includes a question, an answer with code snippets, and expected outputs. The exercises are designed to help users practice basic programming concepts and syntax in Python.

Uploaded by

yorainbow28
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/ 14

Using PRINT function:-

Q.1 To print personal information like Name, Father's Name,


Class, School Name
Answer -Print personal details
print("Name: John Doe")
print("Father’s Name: Mr. Doe")
print("Class: 10")
print("School Name: XYZ High School")
# Output:
# Name: John Doe
# Father’s Name: Mr. Doe
# Class: 10
# School Name: XYZ High School
print() # Blank line for readability

Q2 To find square of number 50BA


Answer -Find the square of 50
square = 50**2
print("Square of 50:", square)
# Output: Square of 50: 2500
print() # Blank line for readability
•Q3: To find the product of two numbers 25 and 50.
Answer - Find the product of 25 and 50
product = 25 * 50
print("Product of 25 and 50:", product)
#Output: Product of 25 and 50: 1250
print() # Blank line for readability.
Q4: To convert length given in kilometres into meters.
Answer -Convert length given in kilometers to meters (1 km =
1000 m)
kilometers = 5 # Example value
meters = kilometers * 1000
print(kilometers, "km in meters:", meters)
#Output: 5 km in meters: 5000,
print() #Blank line for readability.
•Q5: To print the table of 25 up to five terms.
Answer -Print the table of 25 up to five terms
print("Multiplication Table of 25:")
for i in range(1, 6):
print("25 x", i, "=", 25 * i)
# Output:
# Multiplication Table of 25:
# 25 x 1 = 25
# 25 x 2 = 50
# 25 x 3 = 75
# 25 x 4 = 100
# 25 x 5 = 125
print() # Blank line for readability
Q6: To calculate Simple Interest if the principle_amount =
5000 rate_of_interest = 3.5 time = 10
Answer -Calculate Simple Interest
principal_amount = 5000
rate_of_interest = 3.5
time = 10
simple_interest = (principal_amount * rate_of_interest *
time) / 100
print("Simple Interest:", simple_interest)
#Output: Simple Interest: 1750.0
Using the INPUT function:-

Q7: To calculate Area and Perimeter of a square


Answer- side = float(input("Enter the side length of the
square: "))
area = side ** 2
perimeter = 4 * side
print("Area of square:", area)
print("Perimeter of square:", perimeter)
# Example Input: 5
# Output:
# Area of square: 25.0
# Perimeter of square: 20.0
Q8:To calculating average marks of 5 subjects
Answer -marks = []
for i in range(5):
mark = float(input(f"Enter marks for subject {i+1}: "))
marks.append(mark)
average = sum(marks) / len(marks)
print("Average Marks:", average)
#Example Input: 80, 85, 78, 90, 88
#Output:
#Average Marks: 84.2
Q9: To calculate discounted amount with discount %.
Answer- original_price = float(input("Enter the original
price: "))
discount_percent = float(input("Enter the discount
percentage: "))
discount_amount = (original_price * discount_percent) / 100
final_price = original_price - discount_amount
print("Discounted Price:", final_price)
# Example Input: 1000, 10
# Output:
# Discounted Price: 900.0
Using the LIST function:-

Q10: Create a list in Python of children selected for science


quiz with following names-
Arjun, Sonakshi, Vikram, Sandhya, Sonal, Isha, Kartik
Perform the following tasks on the list in sequence- 1)Delete
the name "Vikram" from the list.
• Add the name "Jay" at the end
• Remove the item which is at the second position.
Answer - #Create list
students = ["Arjun", "Sonakshi", "Vikram", "Sandhya",
"Sonal", "Isha", "Kartik"]
print("Original List:", students)
#Output: Original List: ['Arjun', 'Sonakshi', 'Vikram', 'Sandhya',
'Sonal', 'Isha', 'Kartik']

#Delete the name "Vikram"


students.remove("Vikram")
print("After Removing 'Vikram':", students)
#Output: After Removing 'Vikram': ['Arjun', 'Sonakshi',
'Sandhya', 'Sonal', 'Isha', 'Kartik']

#Add the name "Jay" at the end


students.append("Jay")
print("After Adding 'Jay':", students)
#Output: After Adding 'Jay': ['Arjun', 'Sonakshi', 'Sandhya', 'S
Q11: Create a list num=[58,25,45,69,78,14,50]
1) print the length of the list.
2) print the elements from first to fifth position using
positive indexing.
3)print the elements from position second to fourth using
negative indexing
Answer -# Create a list
num = [58, 25, 45, 69, 78, 14, 50]

# Print the length of the list


print("Length of the list:", len(num))

# Print elements from first to fifth position using positive


indexing
print("Elements from first to fifth position:", num[:5])
# Print elements from second to fourth position using
negative indexing
print("Elements from second to fourth position using
negative indexing:", num[-6:-3])
Output:Length of the list: 7
Elements from first to fifth position: [58, 25, 45, 69, 78]
Elements from second to fourth position using negative
indexing: [25, 45, 69]
Q12: Create a list of first 10 odd numbers, add 1 to each list
item and print the final list.
Answer -# Create a list of first 10 odd numbers
odd_numbers = [i for i in range(1, 20, 2)]

# Add 1 to each element


new_list = [x + 1 for x in odd_numbers]

# Print the final list


print("Modified odd number list:", new_list)
Output:Modified odd number list: [2, 4, 6, 8, 10, 12, 14, 16,
18, 20]
Q13: Create a list List_1=[50,70,20,40,80]. Add the elements
[10,45,63,99] using extend function.
Now sort the final list in ascending order and print it.
Answer -# Create a list
List_1 = [50, 70, 20, 40, 80]

# Add elements using extend function


List_1.extend([10, 45, 63, 99])

# Sort the list in ascending order


List_1.sort()

# Print the sorted list


print("Sorted list:", List_1)
Output:Sorted list: [10, 20, 40, 45, 50, 63, 70, 80, 99]
Using (IF, FOR, WHILE) Looping:

Q14: Write a Program to check if a person can apply for


Driving Licence.
Answer -# Check if a person can apply for a driving license
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible for a driving license.")
else:
print("You are not eligible for a driving license.")
Output:Enter your age: 16
You are not eligible for a driving license.
OR
Enter your age: 20
You are eligible for a driving license.
Q15:To find percentage of a student & check the grade.
Answer -# Input marks for subjects
marks = []
subjects = int(input("Enter the number of subjects: "))

for i in range(subjects):
mark = float(input(f"Enter marks for subject {i+1}: "))
marks.append(mark)

# Calculate percentage
percentage = sum(marks) / subjects

# Determine grade
if percentage >= 90:
grade = "A"
elif percentage >= 80:
grade = "B"
elif percentage >= 70:
grade = "C"
elif percentage >= 60:
grade = "D"
else:
grade = "F"

# Print results
print(f"Percentage: {percentage:.2f}%")
print(f"Grade: {grade}")
Output: Enter the number of subjects: 3
Enter marks for subject 1: 85
Enter marks for subject 2: 90
Enter marks for subject 3: 78
Percentage: 84.33%
Grade: B
Q15: Input a number and check if the number is positive,
negative or zero and display an appropriate message.
Answer -num = float(input("Enter a number: "))
if num > 0:
print("The number is positive.")
elif num < 0:
print("The number is negative.")
else:
print("The number is zero.")
Output -Enter a number: -5
The number is negative.
Q16: Input a character & check whether it is an UPPERCASE,
lowercase or a digit or any other special character.
Answer -char = input("Enter a character: ")

if char.isupper():
print("It is an UPPERCASE letter.")
elif char.islower():
print("It is a lowercase letter.")
elif char.isdigit():
print("It is a digit.")
else:
print("It is a special character.")
Output -Enter a character: A
It is an UPPERCASE letter.
Q17: Input three numbers and print the largest of three
numbers using if statement.
Answer - a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
c = float(input("Enter third number: "))

if a >= b and a >= c:


largest = a
elif b >= a and b >= c:
largest = b
else:
largest = c
print("The largest number is:", largest)
Output: Enter first number: 10
Enter second number: 25
Enter third number: 15
The largest number is: 25
Q18: To print first 10 natural numbers.
Answer -print("First 10 natural numbers:")
for i in range(1, 11):
print(i, end=" ")
Output:First 10 natural numbers:
1 2 3 4 5 6 7 8 9 10
Q19: To print first 10 even numbers & Odd numbers.
Answer -print("First 10 even numbers:")
for i in range(2, 21, 2):
print(i, end=" ")

print("\nFirst 10 odd numbers:")


for i in range(1, 20, 2):
print(i, end=" ")
Output:First 10 even numbers:
2 4 6 8 10 12 14 16 18 20

First 10 odd numbers:


1 3 5 7 9 11 13 15 17 19
Q20:Input Salary and Years of Service. If the number of
years are more than 5 then give an extra bonus of 15%
Display the net salary after adding the bonus.
Answer-salary = float(input("Enter salary: "))
years_of_service = int(input("Enter years of service: "))
if years_of_service > 5:
bonus = salary * 0.15
salary += bonus
print("Net salary after bonus:", salary)
Output:Enter salary: 50000
Enter years of service: 6
Net salary after bonus: 57500.0
Q21:Input length & breath & display whether it is a square
or not.
Output:Enter length: 5
Enter breadth: 5
It is a square.
Q22:Input a number between 1 and 7 and display the
weekday based on the number entered.
Answer -days = ["Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"]
num = int(input("Enter a number (1-7): "))
if 1 <= num <= 7:
print("The weekday is:", days[num - 1])
else:
print("Invalid input! Please enter a number between 1 and
7.")
Output:Enter a number (1-7): 3
The weekday is: Wednesday.

You might also like