Arvin Python Project
Arvin Python Project
Program 1
Output:
Enter the Height Of The Triangle: 10
Enter the Base Of The Triangle: 5
Area Of Triangle: 25.0 cm sq
Output:
Enter Value of a : 10.5
Enter Value of b : 9.5
a= 9.5 and b= 10.5
Output:
Enter The Celsius Temperature : 37
37.0 Degree Celsius Temperature in Fahreheit is 98.6 Fahrenheit
Program 2
A) Write a Python Program to Check if a Number is Odd or Even
Output:
Output:
sum=0
x=len(str(n))
copy_n=n
while(n>0):
digit=n%10
sum=sum+(digit**x)
n=n//10
if(sum==copy_n):
print("The Entered Number is an Armstrong Number")
else:
print("The Entered Number is a NOT an Armstrong Number")
Output:
Program 3
def is_fibonacci(n):
if n <= 0:
return False
else:
return is_perfect_square(5*n*n + 4)
or is_perfect_square(5*n*n - 4)
def is_perfect_square(x):
sqrt_x = int(x ** 0.5)
return sqrt_x * sqrt_x == x
if is_fibonacci(n):
print("The Entered Number is a Fibonacci Number")
else:
print("The Entered Number is NOT a Fibonacci Number")
Output:
sum=0
if (n<=0):
print("Enter a Positive Natural Number Please !")
else:
for i in range (1,n+1):
sum=sum+(i*i*i)
print(“Sum = ”,sum)
Output:
Enter the Value of n , For Which You Want the Cube of First n Natural
Numbers : 9
Sum = 2025
n=int(input("Enter The Value of n For Which You Want To Print All The
Odd Numbers in That Range n : "))
Odd=0
for i in range(1,n+1):
if (i%2==0):
continue
else:
Odd=i
print(Odd," ",end="")
Output:
Enter The Value of n For Which You Want To Print All The Odd Numbers
in That Range n : 9
1 3 5 7 9
Program 4
try:
n = int(input("Enter the Number Of Rows For Pascal's Triangle: "))
if n <= 0:
raise ValueError("Please enter a positive integer.")
triangle = [[1]]
except ValueError as e:
print(f"Error: {e}")
Output:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
for i in range(1,n+1):
for j in range (n,0,-1):
print(i,end="")
print()
n=n-1
Output:
11111
2222
333
44
5
Program 5
Write a program with a function that accepts a string from keyboard and create a new
string after converting character of each word capitalized. For instance, if the sentence is
“stop and smell the roses” the output should be “Stop And Smell The Roses”
def capitalize_words(str):
words = str.split()
capitalized_words = [word.capitalize() for word in words]
return ' '.join(capitalized_words)
Output:
Enter a String: arvin
Capitalized String: Arvin
Program 6
A) Write a program that accepts a list from user. Your program should reverse the content
of list and display it. Do not use reverse () method
list=[]
n=int(input("No. Of Elements in List: "))
for i in range(0,n):
ele=int(input(f"Enter the Element {i+1}: "))
list.append(ele)
a=list[::-1]
print("Reversed List:",a)
Output:
B) Find and display the largest number of a list without using built-in function max ().
Your program should ask the user to input values in list from keyboard
list=[]
n=int(input("No. Of Elements in List: "))
for i in range(0,n):
ele=int(input(f"Enter the Element {i+1}: "))
list.append(ele)
list.sort()
print("The Largest Number in the List is",list[-1])
Output:
No. Of Elements in List: 5
Enter the Element 1: 0
Enter the Element 2: 1000
Enter the Element 3: 1
Enter the Element 4: 2
Enter the Element 5: 9
The Largest Number in the List is 1000
Program 7
Find the sum of each row of matrix of size m*n
Output:
Enter The No. Of Rows: 2
Enter The No. Of Columns: 3
Enter the Element 1 Of Row 1: 1
Enter the Element 2 Of Row 1: 2
Enter the Element 3 Of Row 1: 3
Enter the Element 1 Of Row 2: 4
Enter the Element 2 Of Row 2: 5
Enter the Element 3 Of Row 2: 6
Sum Of Elements of Row 1 = 6
Sum Of Elements of Row 2 = 15
Program 8
A) Write a program that reads a string from keyboard and display:
* The number of uppercase letters in the string.
* The number of lowercase letters in the string.
* The number of digits in the string.
* The number of whitespace characters in the string
Output:
Output:
Output: