Python Assignment Program
Python Assignment Program
1. Input Initial velocity (u), acceleration (f) and time duration (t) from the
user and find the final velocity (v) where v = u + f t.
Answer:-
v = u+f*t;
output
import math
pi = math.pi
total_Surface_Area = 2*pi*r*(r+h)
volume = pi*r*r*h
output
if num%2==0:
print("Given Number ",num," is Even")
elif num == 0:
print("Number is Zero")
else:
print("Given Number ",num," is Odd")
output:-
Enter a Number: 5
Given Number 5 is Odd
4.Input 3 sides from the user and check whether triangle can be formed or not. If
yes find the perimeter and area of the triangle.
Answer:-
# Input three values from the user
side_a = float(input("Enter the length of side a: "))
side_b = float(input("Enter the length of side b: "))
side_c = float(input("Enter the length of side c: "))
output:-
Enter the length of side a: 10
Enter the length of side b: 10
Enter the length of side c: 10
The input values form a triangle with perimeter 30.0.
5.Input a year from the user and check whether it is leap year or not.
Answer:-
6.Input a natural number (n) and display the sum of all the natural numbers till n.
Answer:-
output:-
8.Input a positive integer and display all the series: 1, 4, 7, 10, ….., n
Answer:-
9.Input a positive integer and find the sum of all its digits.
Answer:-
10.Input 2 integers and display the numbers within the given range which are
divisible by 3 or 5.
Answer:-
# Ensure that the starting integer is less than or equal to the ending integer
if start_num > end_num:
print("Invalid input. The starting integer should be less than or equal to the ending
integer.")
else:
# Display numbers within the range that are divisible by 3 or 5
print(f"Numbers divisible by 3 or 5 within the range {start_num} to {end_num}:")
for num in range(start_num, end_num + 1):
if num % 3 == 0 or num % 5 == 0:
print(num)
output:-
Enter the starting integer: 4
Enter the ending integer: 10
Numbers divisible by 3 or 5 within the range 4 to 10:
5
6
9
10
11.Input a string check whether in upper case. If yes, convert to lower case.
Answer:-
# Check if s1 + s2 is equal to s2 + s1
if s1 + s2 == s2 + s1:
print("s1 + s2 is equal to s2 + s1.")
else:
print("s1 + s2 is not equal to s2 + s1.")
ouput:-
Enter the first string (s1): suman
Enter the second string (s2): shah
s1 + s2 is not equal to s2 + s1.
13.Input a list, check how many are odd numbers, how many are even numbers.
Answer:-
# Iterate through the values and calculate the sum of numerical values
for value in values:
# Check if the value is a numerical value (integer or float)
if value.replace(".", "", 1).isdigit(): # Removing decimal point for float check
sum_numerical_values += float(value)