Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Due date: W7 Thursday: 18/03/2021. 23:55 pm (through Moodle The purpose of this assignment is to practice the use of Python input/output, modules and selection

image text in transcribed
image text in transcribed
image text in transcribed
Due date: W7 Thursday: 18/03/2021. 23:55 pm (through Moodle The purpose of this assignment is to practice the use of Python input/output, modules and selection control structures to develop a solution to the given problem. Your solution will consist of two parts: your name, university id, section number and your program design (written as comments at the beginning of your program by defining the problem statement, input/output data and the algorithm in pseudocode), () The corresponding Python program. Problem Definition The factorial of a number n (written n!) is the number times the factorial of itself minus one, and the factorial of 1 is, by definition, equals to I. For example, the factorial of 2 is 2*1!=2*1, and the factorial of 3 is 3*2! = 3*2*1 = 6, and so on. Implementing this definition using a computer program is relatively slow, instead Sterling's formula is used as an approximation of the factorial for large values. Sterling's formula is defined as follows: n! = e-n" 2n The exp(x) function in the math module gives the value of e raised to the power of x Write a Python program that: 1. Requests the user to enter 5 integer values of n greater than 10. It should check a. if all entered values are greater than 10, then your program should: output the message: "Thanks for entering 5 valid numbers greater than 10" calculate their factorial using sterling's formula allow the users to enter one of the following format types, which should be used to print the factorials of the numbers D Default representation S Scientific representation with default precision N Non Scientific representation with 2 decimal precisions validate the format type: if the format type is "Default representation", then it should display the results in a tabular format using "Default representation" as shown in Figurel else if the format type is "Scientific representation with default precision", then it should display the results in a tabular format using "Scientific representation with default precision" as shown in Figure2. else if the format type is "Non Scientific representation", then it should display the results in a tabular format using "Non Scientific representation with 2 decimal precisions" as shown in Figure3. otherwise, your program should display the following message as shown in Figure4: "You entered an invalid format type" b. otherwise, your program should output the following message: "Sorry you entered wrong numbers BYE" Figurel shows a sample run of the program with valid numbers and Default representation format type. Figure2 shows a sample run of the program with valid numbers and Scientific representation format type. Figure3 shows a sample run of the program with valid numbers and Non Scientific representation format type. Figure4 shows a sample run of an invalid format type and Figures shows a sample run of the program with invalid numbers. Peter Sisters greater than 112 1135 Plaster 5 Sternumbers greater the 2013 Thanks for et valdes prester than 18 Please Enter the format type: Defaut representation 5 Scinti presentati dal precis or the forte Scintificeret altres Scientific representation at 2 del precision Output fort citiem Default representation Sterling Value Sterlinge 11 12 13 S4 15 27 LAM 2219 Figurel: Sample run of the program with valid numbers and Default representation format type. Figure2: Sample run of the program with valid numbers and Scientific representation format type. Please enter integrers greater than 3:11211315 Thanks for entering valides ruter than Please later the format type Defelet pretation 5 Scintification and dealt rii Scientific representation and decimale 9232_SMS Seluti , dir: Please enter integer runters preater than 18. 11 12 13 14 15 Thanks for stering velit ubers greater than 8 Please Enter the font to 5 Scientific representation and default precision or Scientific representation and 2 decimel precision Non-Scientific representation Precision Sterling Valu 396112. 12 4796786.47 32723475.29 17. 15 10. os entered wirelid forset type Figure3: Sample run of the program with valid Figure Sample run of the program with invalid numbers and Non Scientific representation format format type. type. Console 1/A In [19]: runfile("C:/zuhoor_Hard disk/Zuhoor 2020/COMP 2101/Python COMP2101_Spring2021/H/Hw2/w2 Sample Solution SP2021_zuhoor.py", wdir='C:/ zuhoor_Hard disk/Zuhoor 2020/COMP2101/Python COMP2101_Spring2021/H/H.2") Please enter 5 integer numbers greater than 10: 11 9 13 16 12 Sorry you entered worng numbers ============> BYE In [20]: Figure5: Sample run of the program with invalid numbers DELIVERABLES Submit a Python source file: HW2 ID NAME_Secipy. For instance, if your ID is 38000, your NAME is Ahmed and your section is 21, then you should submit a file HW2_38000_Ahmed Sec21.py. Your source file will consist of two parts: a) Header includes documentation with your name, your student id, and section number, the problem statement (a short description of the purpose of your code), data description (input, and output variables used in the program including constants), algorithm in pseudocode. b) Python program mark /3 Grading Table Item Part(i): your name, Id and program design (written as a comments at the beginning of your program) Part(i): Your Python Program Style (Comments, indentation) Use of constants and variables naming (accordance to Python convention) Prompting & Reading data from keyboard Validation of data using if and/or nested if statement, giving appropriate message and ending the program for invalid data Calculating Sterling's values Displaying results using the first format Displaying results using the second format Displaying results using the third format Program compiles and runs without errors Proper Naming & Submission TOTAL 71 71 /2 14 12 1 /2 2 11 /1 720 Late Submission Policy: a) 1-24 hours: 25% of the mark will be deducted. (b) > 24 hours: Not accepted. Code of ethics: It is essential that each student solve all programming assignments, lab tests and exams individually unless instructed otherwise, c.g., for group projects. Copying, plagiarism, collusion, switching, and falsification are violations of the university academic regulations. Students involved in such acts will be severely penalized. The department has adopted a firm policy on this issue. A zero mark will be assigned the first time a student is caught involved in copying and his her name will be added to a watch list maintained by the Head of Department. Further repeated involvements in copying will cause the student to get an F grade in that course. This is in line with the university academic regulations

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions