M.Sc Computer Application

M.Sc Python Programming Assignment 10

M.Sc Python Programming Assignments Assignment 10 Question:   Write a program (using functions!) that asks the user for a long string containing multiple  words. Print back to the user the same string, except with the words in backwards order. E.g “ I am Msc student” is :”student Msc am I” Code: def reverse_words(string): words = string.split() …

M.Sc Python Programming Assignment 10 Read More »

M.Sc Python Programming Assignment 9

M.Sc Python Programming Assignments Assignment 9 Question:   Write a program that asks the user how many Fibonnaci numbers to generate and then    generates them. Code: def generate_fibonacci_numbers(count): fibonacci_numbers = [] if count >= 1: fibonacci_numbers.append(0) if count >= 2: fibonacci_numbers.append(1) if count > 2: for i in range(2, count): fibonacci_numbers.append(fibonacci_numbers[i-1] + fibonacci_numbers[i-2]) return …

M.Sc Python Programming Assignment 9 Read More »

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 »

Tech Amplifier Final Logo