Chandigarh University Python Assignment Sem 4
Chandigarh University Python Assignment Sem 4
University
Bachelors of
computer
application
Python
Programming
Graded
Assignment
Name:Deepit Chikersal
UID Number:O22BCA11083
Python Programming
Assignment
Answer:-
def main():
try:
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
if __name__ == "__main__":
main()
2. Write a Python program to create all possible strings by
using 'a', 'e', 'i', 'o', 'u'. Use the characters exactly once.
Answer:-
def generate_strings(characters):
# Generate all permutations of the characters
perms = permutations(characters)
# Join each permutation into a string and add to the result list
result = [''.join(perm) for perm in perms]
return result
def main():
characters = ['a', 'e', 'i', 'o', 'u']
all_strings = generate_strings(characters)
if __name__ == "__main__":
main()
3. Write a Python program to sum of two given integers.
However, if the sum is between 15 to 20 it will return 20
Answer:-
def sum_with_condition(a, b):
# Calculate the sum of the two integers
total = a + b
def main():
# Take user input for two integers
try:
num1 = int(input("Enter the first integer: "))
num2 = int(input("Enter the second integer: "))
if __name__ == "__main__":
main()
4. Write a Python program to calculate the length of a string
Answer:-
def calculate_string_length(input_string):
# Use the len() function to calculate the length of the string
length = len(input_string)
return length
def main():
# Take user input for a string
input_string = input("Enter a string: ")
if __name__ == "__main__":
main()
5.Write a Python program to find the median among three
given numbers
def find_median(num1, num2, num3):
# Put the numbers in a list
numbers = [num1, num2, num3]
return median
def main():
# Take user input for three numbers
try:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
if __name__ == "__main__":
main()