question archive Instructions The following guidelines should be followed and will be used to grade your homework: • All code to be implemented and submitted as a jupyter notebook (
Subject:Computer SciencePrice:12.86 Bought3
Instructions The following guidelines should be followed and will be used to grade your homework: • All code to be implemented and submitted as a jupyter notebook (.ipynb) file. Submit a single ipynb file. • This is an individual homework assignment; no group submissions will be accepted. If you discuss in groups, please write your code individually and submit. • Sample runs shown in the question should be used as a guide for implementation. However extensive testing needs to be done on your code to deal with all test cases that might possibly be executed. • The high level algorithm of how you are solving the problem should be documented in the cell preceding the code in markdown language. • The instructions for running of each cell and the expected results should be documented in the cell preceding the code using markdown language. • Every code segment in the jupyter notebook cells should be well documented with comments. Use # in the code to provide comments and they should explain the algorithm step and what the code segment is doing. • Error checking in your code is very important and differentiates a high quality programmer from a low quality one. Hence you should account for invalid user inputs, infinite loops, out of range results, etc. and resolve them by appropriate error messages. Use try/except blocks, if statements and other python code constructs to deal with unexpected errors and deal with them gracefully. The homework will be graded for robustness of your code. 1. (10 points) Implement a program that requests three strings from the user. Your program should concatenate the first two strings (string 2 + string1) in reverse order and compare the concatenated string with the third string, the program should concatenate the two strings in the reverse order (string2 + string1) and compare it with the third string and print “They are equal in the reverse order”. If this test also fails, your program should print “They are not equal”. A partial sample run is shown below: Enter First string: bye! Enter second string: Good Enter third string: Goodbye! The two strings are equal in the reverse order Enter First string: 12 Enter second string: bye! Enter third string: 12bye! They are not equal 2. (10 points) Write a Python program that reads in 4 integers or 5 integers (user first determines 4 or 5 integers) and displays the following: a. the average of the numbers b. the minimum of the numbers c. the maximum of the numbers d. the median of the numbers. Note that if there were 2 numbers that qualify for the median, you will calculate and display the mean of the 2 numbers A sample run is shown below: Do you want to use 4 or 5 integers: 4 Enter first number: 7 Enter second number: 10 Enter third number: 1 Enter fourth number:0 The average of 7, 10 ,1 and 0 is: 4.5 The minimum of the four numbers is: 1 The maximum of the four numbers is: 10 The median of the four numbers:4 Do you want to use 4 or 5 integers: 5 Enter first number: 7 Enter second number: 10 Enter third number: 1 Enter fourth number: 6 Enter fifth number,6 The average of 7, 10 ,1 ,6 and 6 is: 6.0 The minimum of the four numbers is: 1 The maximum of the four numbers is: 10 The median of the four numbers is: 6 3. (10 points) A number that is greater than 1 that is not a prime number is called a composite number. An integer, greater than 1, that is only divisible by 1 and itself is called a prime number. The integers 0 and 1 are neither prime nor composite. Write a python program that requests a positive integer from the user, determines if it is a composite, a prime or neither prime or composite and prints the message. You can choose to use iterative loops to repeatedly run this script or have the user run the script for every input. Please specify instructions on which method you are using to run the code in markdown language above the code cell. Sample runs are shown below: Enter positive integer: 3 It is a prime Enter positive integer: 4 It is a composite Enter positive integer: 1 It is neither prime nor composite Enter positive integer: -5 Error: You did not enter a positive integer Enter positive integer: -2.5 Error: You did not enter a positive integer Enter positive integer: Hi Error: You did not enter a positive integer 4. (10 points) Write a program that takes as input two opposite corners of a rectangle: (x1,y1) and (x2,y2) – float or integer only. Finally, the user is prompted for the coordinates of a third point (x,y). The program should print value “Yes,it lies within the rectangle” or “Not, It doesn’t lie in the rectangle” based on whether the point (x,y) lies within the rectangle. At the end of each run, the user should be prompted to ask whether then want to continue. Note that the rectangle could fall anywhere in the 2X2 plane of real numbers. Sample runs are shown below Enter x1: 1 Enter y1: 3 Enter x2: 10 Enter y2: 6 Enter x: 4 Enter y: 4 Yes, it lies within the rectangle Do you want to continue: Y Enter x1: 1 Enter y1: 3 Enter x2: 10 Enter y2: 6 Enter x: 4 Enter y: 2 Not, it doesn’t lie in the rectangle Do you want to continue: N Goodbye! 5. (10 points) Implement a Python function called Interest() that takes three arguments:1 a. Time Period (integer) b. Interest Rate (0.0 to 100.0% as a float) c. A principle amount (float) Write a main program that requests the 3 numbers (perform error checking for input types (float vs. integer). Also, in the main program you should call your defined function Interest () that takes 3 arguments and display the result of the simple interest. Your function should return the Final Amount (i.e., a principal amount + interest). **The formula for a simple interest is (Principle*InterestRate*Years)/100 ***The formula for the Final Amount is (Principle + simple interest) If the result is an integer, the return type should be an integer. If the result is a floating-point number, the return type should be a floating-point number. Write your function definition in one cell and the function calling main program below it or in a different cell in Jupyter Notebook. I will be testing this program by modifying your program that calls this function. Enter Time Period: 1 Enter Interest Rate: 10.0 Enter principle: 100.0 Simple Interest need to be paid: 10.0 Final Amount need to be paid:110 Explanation: Simple Interest = (Time Period*Interest Rate*Principle)/100 = (1*10*100)/100 = 10 Final Amount = Simple Interest + Principle = 10 + 100 = 110
Purchased 3 times