Please write down all the required codes for Exercise 1, 2, 3 and 4 [in the same order] in ONE FILE. In addition, print a message before start of each exercise (e.g. print("Exercise 1") etc). When running your code, make sure that Exercises 1 and 2 just print the required numbers where no input is expected from the user. Then, relevant messages must be displayed to inform the user to provide appropriate input for Exercises 3 and 4. If you miss to complete any exercise, it is then very important to include the print message including the exercise number for the ones you have completed just before their starting line in your code (e.g. print(Exercise 1) etc).

Exercise 1

A narcissistic number refers to all numbers that can be written as the sum of each digit in the number to the power of its length (number of digits in the number) for example 153 and 9474 are narcissistic number since they can be written as:

153=13 + 53 + 33
9474=94 + 44 + 74 + 44

For more information see: http://mathworld.wolfram.com/NarcissisticNumber.html. Write a programming code to print the first 20 narcissistic numbers. Do NOT use list, string, list/string operations or any library for this code. Please consider 1 as the first narcissistic number.

Hint: As explained in the webinar, to calculate the length of your number, you need to divide your integer by 10 and use the integer quotient continuously until you reach zero. Then, to retrieve each digit you can use the modulus operator (%).

Exercise 2

For this exercise, print all prime numbers less than 1000. Print 20 numbers in each line [do not forget to add space between numbers]. Hint: A prime number can be divided, without a remainder, only by itself and by 1. Do NOT use list, string or list/string operations or any library for this code. Please consider 1 as a prime number too.

Exercise 3

First, your code needs to get two positive integers (non-zero) as input by the user. Please display relevant information to the user to understand what input the program needs. Then, calculate the greatest common divisor of the two positive integers (which is the largest integer that divides each of the integers) as the input by the user. Then, print out the result which must be the greatest common divisor. Do NOT use list, string or list/string operations or any library for this code.

Two examples are provided as below:

Example #1:

Please enter the first integer [positive integer]: 48
Please enter the second integer [positive integer]: 18
The greatest common divisor is: 6

Example #2:

Please enter the first integer [positive integer]: 12
Please enter the second integer [positive integer]: 48
The greatest common divisor is: 12

Your program's messages and output are in green colour.

You may customize or format input/output messages as you desire. Display relevant messages if the input is not [non-zero positive].

Exercise 4

To calculates sin () using Taylor series, use the following definition: The function sin () can be calculated using the Taylor series:

For more information see https://en.wikipedia.org/wiki/Taylor_series Where the factorial is calculated as:

x! = 1 x 2 x ... x (X − 1) x X

For example:

(2n + 1)! = 1 x 2 x ... x (2n) x (2n + 1)

Write Python program to calculate sin (X) using Taylor series (see above), of course n cannot go to infinity. Therefore, only calculate about 16 terms (use a for loop n = 0 to 15). The input X must be entered by the user in DEGREE [then your code needs to convert it to radians using math.radians]. You may use string for input validation or output formatting only.

An example of your program:

Please enter x in degree: 45
The calculated sin of x is: [your output]

You may customize or format input/output messages as you desire.

Your output should be close enough [given 16 terms of Taylor series as above] to the output of math library's sin function.

To calculate factorial, you need to write loops. You are allowed to write one function within your MAIN FILE to calculate factorial. Any available function in math library to calculate factorial is NOT allowed (e.g. math.factorial).

For this purpose, you may import the math library and use math.sin. You do NOT need to include this testing as part of your program. The testing will give you an idea if you get a good/correct approximation for sin values. Hint: Use math.radians to convert degree to radians to obtain different values of X as above.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.