M.Sc Python Programming Assignment 8
M.Sc Python Programming Assignments Assignment 8 Question: To check whether a number is palindrome or not. (using recursion and without recursion). Code: def is_palindrome_recursive(word): if len(word)
M.Sc Python Programming Assignments Assignment 8 Question: To check whether a number is palindrome or not. (using recursion and without recursion). Code: def is_palindrome_recursive(word): if len(word)
M.Sc Python Programming Assignments Assignment 7 Question: To determine whether the number is prime or not Code: def is_prime(number): if number < 2: return False for i in range(2, int(number ** 0.5) + 1): if number % i == 0: return False return True number = int(input("Enter a number: ")) if is_prime(number): print(f"{number} is …
M.Sc Python Programming Assignments Assignment 6 Question: Write a program that returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists of different sizes. Code: def find_common_elements(list1, list2): common_elements = [] for element in list1: if element in list2 and …
M.Sc Python Programming Assignments Assignment 5 Question: Write a program that prints out all the elements of the list that are less than 10 Code: def print_elements_less_than_10(lst): for element in lst: if element < 10: print(element) # Example list my_list = [4, 12, 6, 9, 15, 2, 7] print("Elements less than 10:") print_elements_less_than_10(my_list) Output: …
M.Sc Python Programming Assignments Assignment 4 Question: Write a program which can compute the factorial of a given number. Code: def compute_factorial(number): factorial = 1 if number < 0: return "Factorial is not defined for negative numbers." elif number == 0: return 1 else: for i in range(1, number + 1): factorial *= i …
M.Sc Python Programming Assignments Assignment 3 Question: Write a program which will find all such numbers which are divisible by 7 Code: start = int(input(“Enter the starting number: “)) end = int(input(“Enter the ending number: “)) divisible_by_7 = [] for number in range(start, end + 1): if number % 7 == 0: divisible_by_7.append(number) print(“Numbers divisible …
M.Sc Python Programming Assignments Assignment 2 Question: Write a program to check whether the number is even or odd, print out an appropriate message to the user. Code: def check_even_odd(number): if number % 2 == 0: return “even” else: return “odd” number = int(input(“Enter a number: “)) result = check_even_odd(number) message = f”The number {number} …
M.Sc Python Programming Assignments Assignment 1 Question: Create a program that asks the user to enter their name and their age. Print out a message addressed to them that tells them the year that they will turn 100 years old. Code: import datetime def calculate_year_of_turning_100(age): current_year = datetime.datetime.now().year year_of_turning_100 = current_year + (100 – age) …
TY B.sc(computer application) Control Statements and Loops 1) Write a Python Program to Check if a Number is Positive, Negative or Zero def check_number(num): if num > 0: print(“The number is positive.”) elif num < 0: print(“The number is negative.”) else: print(“The number is zero.”) # Test the program with different numbers check_number(10) # Output: …
Programming Assignments:TY B.sc(computer application) Read More »
M.Sc AI Practical Assignment Solution 6 Question: Write a Python program to implement Regression algorithm Code: Output: Estimated coefficients: b_0 = 1.2363636363636363 b_1 = 1.1696969696969697