Reference no: EM133059365
Learning Activity: Programming Exercises
Exercise 1. Prime number (Advanced)
From the last learning activity, you learnt how to determine whether a particular number is a prime number. In this learning activity, you will write a Python program that outputs all prime numbers from 1 to a given number. The program will first ask the user to type in a positive number, then output all the prime numbers from 1 to that number (inclusive), separated by comma.
Sample input/output:
>>> Enter a positive number:
>>> 100
>>> 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
This learning activity asks you to write a program.
Please upload your code as a Python code file (.py file) to Module 3.2 Programming Exercises - Difficult Discussion Forum and do not copy and paste your code in the discussion forum text editor as the indentation may be lost. Indentations in Python indicate code blocks and scope and is part of the code.
Please check other students' code and comment on why you agree, disagree or can provide help with another students' post. Please reply to at least two other students' posts.
Exercise 2. Tayler expansion
In this exercise, you are going to write a Python program that approximate the first n terms of the following equation:
1 + 2/1! + 22/2! + 23/3! + 24/4! ......,
where m! is the factorial of m, that is,
m! = 1 × 2 × 3 × ... × m
For example, 5! = 120 (the production from 1 to 5). 10! = 3628800.
Now write a Python program that allows the user to type in an integer n, your program then calculate the first n terms of the summation in the equation. For example, if the user type in 3, you then need to calculate the result of the first 3 terms:
1+ 2/1! + 22/2! = 1 + 2 + 2 = 5
If the user type in 4, you then need to calculate the result of the first 4 terms:
1+ 2/1! + 22/2! + 23/3! = 1 + 2 + 2 + 1.33 = 6.33
Sample input/output 1:
>>> Enter an integer:
>>> 3
Sample input/output 2:
>>> Enter an integer:
>>> 4
>>> 6.33
This learning activity asks you to write a program.