Reference no: EM132395303
Assignment: Part 1:
Question 1: Write a python program that finds all numbers divisible by 7 but not multiple of 5. The range of number for searching is between 2000 and 3200 (both included). Output should be printed in a comma-separated sequence on a single line.
Question 2: Write a python program that can compute the factorial of a given 2 numbers from the user. The results should be printed in a comma-separated sequence on a single line.
Input number 1: 3
Input number 2: 4
Sample Output: 6, 24
Question 3: Define a python class which has at least two methods:
getString: to get a string from console input.
printString: to print the string in upper case.
You should also include functions to invoke the above-mentioned methods.
Question 4: Write a program that accepts a comma separated sequence of words as input and print the words in a comma-separated sequence after sorting them alphabetically.
Sample input: without,hello,bag,world
Sample output: bag,hello,without,world
Question 5: Write a python program that accepts a sentence and calculate the number of letters and digits in the sentence.
Question 6: Define a function that receives two integer numbers in string form and compute their sum and print it in the console.
Question 7: Write a python program that reads from a text file and print all the unique words of the file in alphabetical order.
Question 8: Write a simple banking program using python that has four options: 1. View balance 2. Make a deposit 3. Make a withdrawal 4. Quit. You must implement classes and object for this program.
Question 9: Write a program that keep track of when our friend's birthdays are, and be able to find that information based on their name. Create a dictionary of names and birthdays. When you run your program it should ask the user to enter a name, and return the birthday of that person back to them. The interaction should look something like this:
Welcome to the birthday dictionary. We know the birthdays of:
Albert Einstein
Benjamin Franklin
Ada Lovelace
Who's birthday do you want to look up?
User Input: Benjamin Franklin #Example
Benjamin Franklin's birthday is 01/17/1706 #This your program should print
Question 10: Given an array of data:
10
5
15
2
7
21
a. Write the code for the selection sort to sort the data and draw a table showing how the data is sorted using selection sort.
b. Write the code for Binary search algorithm to find the value 15 from the sorted array. Draw the tree diagram showing the binary search of the list.
Part 2:
Question 1: Explain what happens when the following recursive function is called with the value 4 as an argument
def example(n) :
if n > o:
print(n)
example(n-1)
Question 2: a. What are instance variables, and what role does the name "self" play in the context of a class definition?
b. How is the lifetime of an object determined? What happens to an object when it dies?
Question 3: Define a method for the Bank class that returns the total assets in the bank (the sum of all account balances).
Question 4: Two playing cards can be compared by rank. For example, an ace is less than a 2. When c1 and c2 are cards, c1.rank< c2.rank expresses this relationship. Explain how a method could be added to the Card class to simplify this expression to c1 < c2.
Question 5: Write a python program that calculates and prints the number of minutes in a year.
Question 6: Using python, write a loop that accumulates the sum of all of the numbers in a list named data. What is the purpose of the dir function and the help function?
Question 7: Write a function called isprime which takes a single integer argument and returns True if the integer is a prime number, and False otherwise. A prime number is a number with only two distinct divisors, 1 and itself.
Note: 1 is therefore not a prime number.
Question 8: Write a Python program that read a line of input from the user until the user enters a blank. The program should print out the total number of occurrences of each letter in the alphabet. These should be printed in alphabetical order. Your program should work like this:
> ./letters
hello world
d 1
e 1
h 1
l 3
o 2
r 1
w 1
Question 9: Why does Python code generate fewer types of syntax errors than code in other programming languages?
Question 10: Write a python program that will perform the operations of simple calculator. The operations are : Addition, subtraction, Multiplication and division. Sample output : Select operation. 1.Add 2.Subtract 3.Multiply 4.Divide Enter choice(1/2/3/4): 3 Enter first number: 15 Enter second number: 14 15 * 14 = 210
Question 11: Identify the error in the following program and write the correct python source code line = raw_input("Type a word") print "You typed", line line = line + "h" num = int(line) print "You typed the number ", num
Question 12: Describe two fundamental differences between terminal-based user interfaces and GUIs.
What roles do the parameters and the return statement play in a function definition?
Question 13: Write a python code to sort the given set of numbers in ascending order. You must not use any built-in functions of python.