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

Python - Project-2 Term 2

Uploaded by

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

Python - Project-2 Term 2

Uploaded by

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

PYTHON PROGRAM

NAME – Vedant Nagvekar


CLASS – 9A ROLL NO. - 37
1. To convert length given in kilometers into meters.
kilometers = float(input("Please Enter the length in kilometers = "))

meter = kilometers * 1000

print("%.2f Kilometers = %.2f Meters" %(kilometers, meter))

2. To calculating average marks of 3 subjects


a=int(input("Enter the marks of first subject: "))

b=int(input("Enter the marks of second subject: "))

c=int(input("Enter the marks of third subject: "))

total=a+b+c

avg=total/3

print("Total marks: ",total)

print("Average marks: ",avg)

3. Create a list in Python Perform the following tasks on the list in sequence-
Print the whole list, Delete, Add the name at the end, Remove the item which is at the second
position.

names = ["Jane", "John", "Jade", "Joe"]

print(names)

del names[1]

1|Page
print(names)

names = ["Jane", "John", "Jade", "Joe"]

names.remove("John")

print(names)

names = ["Jane", "John", "Jade", "Joe"]

names.append("Doe")

print(names)

names = ["Jane", "John", "Jade", "Joe"]

names.insert(2, "Diya")

print(names)

4. Python Program to Print Odd Numbers from 1 to N –


Write a Python Program to Print Odd Numbers from 1 to N using While Loop and For Loop with
an example.

A. Python Program to Print Odd Numbers from 1 to N using For Loop – This Python
program allows the user to enter the maximum limit value. Next, Python is going to
print odd numbers from 1 to the user entered a maximum limit value. In this example,
Python for Loopmakes sure that the odd numbers are between 1 and maximum limit
value.

maximum = int(input(" Please Enter any Maximum Value : "))

for number in range(1, maximum + 1):

if(number % 2 != 0):

2|Page
print("{0}".format(number))

B. Python Program to Print Odd Numbers using While Loop - In this python odd numbers
program, we just replaced the For Loop with While Loop.

maximum = int(input(" Please Enter the Maximum Value : "))

number = 1

while number <= maximum:

if(number % 2 != 0):

print("{0}".format(number))

number = number + 1

5. Python program to find sum of elements in list

# Python program to find sum of elements in list

total = 0

# creating a list

list1 = [11, 5, 17, 18, 23]

# Iterate each element in list

# and add them in variable total

for ele in range(0, len(list1)):

total = total + list1[ele]

# printing total value print("Sum of all elements in given list: ", total)

3|Page
6. Input a number and check if the number is positive, negative or zero and display an
appropriate message

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

if num > 0:

print("Positive number")

elif num == 0:

print("Zero")

else:

print("Negative number")

7. Python program to calculate Simple Interest using user input


The given Python program calculates and prints the simple interest based on principle, rate of
interest, an d year provided by user at run-time.

print("Enter the principal amount: ")

p = int(input())

print("Enter the rate of interest: ")

r = float(input())

print("Enter the number of years: ")

t = float(input())

si = (p*r*t)/100

print("\nSimple Interest Amount: ")

print(si)

4|Page
8. To calculate Surface Area and Volume of a Cuboid
length = float(input(’Please Enter the Length of a Cuboid: ’))

width = float(input(’Please Enter the Width of a Cuboid: ’))

height = float(input(’Please Enter the Height of a Cuboid: ’))

# Calculate the Surface Area

SA = 2 * (length * width + length * height + width * height)

# Calculate the Volume

Volume = length * width * height

# Calculate the Lateral Surface Area

LSA = 2 * height * (length + width)

print("The Surface Area of a Cuboid = %.2f " %SA)

print(" The Volume of a Cuboid = %.2f" %Volume);

print(" The Lateral Surface Area of a Cuboid = %.2f " %LSA)

5|Page

You might also like