0% found this document useful (0 votes)
6 views

Gobind Sir File

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Gobind Sir File

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1. Program to calculate the total marks and percent of five subjects.

subject1 = float(input("Enter marks for Subject 1: "))

subject2 = float(input("Enter marks for Subject 2: "))

subject3 = float(input("Enter marks for Subject 3: "))


subject4 = float(input("Enter marks for Subject 4: "))

subject5 = float(input("Enter marks for Subject 5: "))

total_marks = subject1 + subject2 + subject3 + subject4 + subject5

max_marks = 500

percentage = (total_marks / max_marks) * 100

print(f"Total Marks: {total_marks}")

print(f"Percentage: {percentage:.2f}%")

Output:
2. Program to convert the currency from Rs. To dollar or vice versa.
print("Currency Converter")
print("1. Convert INR to USD")
print("2. Convert USD to INR")

choice = int(input("Enter your choice (1 or 2): "))

conversion_rate = 82.0 # Example conversion rate (1 USD = 82 INR)

if choice == 1:
inr_amount = float(input("Enter amount in INR: "))
usd_amount = inr_amount / conversion_rate
print(f"{inr_amount} INR is equal to {usd_amount:.2f} USD.")
elif choice == 2:
usd_amount = float(input("Enter amount in USD: "))
inr_amount = usd_amount * conversion_rate
print(f"{usd_amount} USD is equal to {inr_amount:.2f} INR.")
else:
print("Invalid choice. Please enter 1 or 2.")

Output:

3. Program to check if entered number is Even or Odd.


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

if number % 2 == 0:
print(number, "is an even number.")
else:
print(number, "is an odd number.")

Output

4. Program to display the following pattern :

1) 1
12

123

1234

Sol:
n=4

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

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

print(j, end=" ")

print()

Output

5) Write a python program to print the Fibonacci series till nth term entered by the user.

Sol:
n = int(input("Enter the number of terms: "))

a, b = 0, 1

for _ in range(n):

print(a, end=" ")


a, b = b, a + b

Output:

6) Program to check if the entered number is prime or not.

Sol:

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


if number > 1:

for i in range(2, int(number ** 0.5) + 1):

if number % i == 0:

print(f"{number} is not a prime number")

break

else:

print(f"{number} is a prime number")


else:

print(f"{number} is not a prime number")

output:
7. Write a program to calculate the grade of the student on the basis of following criteria:

Marks Grades
> = 90 A1
>=80 A2
>=70 B1
>=60 B2
>=50 C1
>=40 C2
>=33 D
<=33 E
Ans:
marks = float(input("Enter the marks obtained by the student: "))
if marks >= 90:
grade = 'A1'
elif marks >= 80:
grade = 'A2'
elif marks >= 70:
grade = 'B1'
elif marks >= 60:
grade = 'B2'
elif marks >= 50:
grade = 'C1'
elif marks >= 40:
grade = 'C2'
elif marks >= 33:
grade = 'D'
else:
grade = 'E'
print(f"The grade for marks {marks} is: {grade}")

Output:
8) Create a list of following elements :

Apple, banana, pineapple, orange

Give the command for the following :

• Add a new element – Guava

• Insert a new element at specific position eg in second position

• Delete the last element.


• Sort the list

Soln:

# Create the initial list


fruits = ["Apple", "Banana", "Pineapple", "Orange"]
print(fruits)
print("Add a new element - Guava")
fruits.append("Guava")
print(fruits)
print("Insert a new element at the second position (index 1) - for example, Mango")
fruits.insert(1, "Mango")
print(fruits)
print("Delete the last element")
fruits.pop()
print(fruits)
print(" Sort the list")
fruits.sort()

# Display the final list


print(fruits)
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy