Tialkoutput 1-15
Tialkoutput 1-15
print("hello world")
OUTPUT
NAME:ABHINAV PAL COURSE: BCA-G1 SEMESTER: 4th
ROLL-NO: 2221037(05) STUDENT ID: 220411449 2.
CODE:
a=7
b=2
# addition print ('Sum: ', a
+ b) # subtraction print
('Subtraction: ', a - b)
# multiplication
print ('Multiplication: ', a * b)
# division
print ('Division: ', a / b) #
floor division
print ('Floor Division: ', a // b)
# modulo
print ('Modulo: ', a % b)
# a to the power b print
('Power: ', a ** b)
OUTPUT:
CODE:
# Python Program to find the area of
triangle a =
b=
c =# Uncomment below to take inputs from
the user
OUTPUT:
5c=6
OUTPUT:
CODE:
x=5y
= 10
NAME:ABHINAV PAL COURSE: BCA-G1 SEMESTER: 4th
ROLL-NO: 2221037(05) STUDENT ID: 220411449 5.
OUTPUT:
CODE:
OUTPUT:
CODE:
print("{0} is Odd".format(num))
OUTPUT:
CODE:
year = 2024
# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year else:
print("{0} is not a leap year".format(year))
OUTPUT:
CODE: num
= 11
# If given number is greater than 1 if
num > 1:
# Iterate from 2 to n / 2 for i
in range(2, int(num/2)+1):
# If num is divisible by any number between
# 2 and n / 2, it is not prime
if (num % i) == 0:
NAME:ABHINAV PAL COURSE: BCA-G1 SEMESTER: 4th
ROLL-NO: 2221037(05) STUDENT ID: 220411449 9.
OUTPUT:
NAME:ABHINAV PAL COURSE: BCA-G1 SEMESTER: 4th
ROLL-NO: 2221037(05) STUDENT ID: 220411449
10. Write a python program to check if a value entered by a user is Palindrome or not.
CODE:
def isPalindrome(s):
return s == s[::-1]
# Driver code s =
"malayalam" ans =
isPalindrome(s)
if ans:
print("Yes") else:
print("No")
OUTPUT:
11. Write a python program to check if a value entered by a user is Armstrong or not.
CODE:
# Python program to check if the number is an Armstrong number or not
NAME:ABHINAV PAL COURSE: BCA-G1 SEMESTER: 4th
ROLL-NO: 2221037(05) STUDENT ID: 220411449
# take input from the user num =
int(input("Enter a number: "))
OUTPUT:
12.Consider a number entered by a user. Now calculate the Factorial of this number.
CODE:
# Define a function named 'factorial' that calculates the factorial of a number 'n' def
factorial(n):
# Check if the number 'n' is 0
if n == 0:
# If 'n' is 0, return 1 (factorial of 0 is 1)
return 1 else:
NAME:ABHINAV PAL COURSE: BCA-G1 SEMESTER: 4th
ROLL-NO: 2221037(05) STUDENT ID: 220411449
# If 'n' is not 0, recursively call the 'factorial' function with (n-1) and multiply it with 'n'
return n * factorial(n - 1)
# Ask the user to input a number to compute its factorial and store it in variable 'n' n
= int(input("Input a number to compute the factorial: "))
# Print the factorial of the number entered by the user by calling the 'factorial' function
print(factorial(n))
OUTPUT:
13. Write a python program to print the Fibonacci sequence upto the range entered by a user.
CODE:
OUTPUT:
14. Write a python program to check whether the number entered by the user is a Perfect number or
not.
CODE:
OUTPUT:
NAME:ABHINAV PAL COURSE: BCA-G1 SEMESTER: 4th
ROLL-NO: 2221037(05) STUDENT ID: 220411449
15. Consider any long string. Now replace each space between two words with the tab (i.e. the space
created when you press the key 'Tab' from your keyboard).
CODE:
OUTPUT: