All Blogs

M.Sc Python Programming Assignment 6

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 Assignment 6 Read More »

M.Sc Python Programming Assignment 5

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 Assignment 5 Read More »

M.Sc Python Programming Assignment 3

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 Assignment 3 Read More »

M.Sc Python Programming Assignment 2

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 Assignment 2 Read More »

M.Sc Python Programming Assignment 1

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) …

M.Sc Python Programming Assignment 1 Read More »

Programming Assignments:TY B.sc(computer application)

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 »

Tech Amplifier Final Logo