Reference no: EM133059361
MIS501 Principles of Programming
Learning Activity 1 - Programming Exercise
Exercise 1. Prime number
Prime number are those positive integers that are divisible only by itself and 1. For example, 2, 3, 5, 7, 11 are all prime numbers. Number 6 is not a prime number because it is divisible also by 2 or 3 in addition to 1 and itself 6.
In this learning activity, you are asked to write a Python program that determines whether a user's input is a prime number or not. The user will type in a positive integer, if it is a prime number, your program should output "Yes, it is a prime number"; otherwise, output "No, it is not a prime number".
Sample input/output 1:
>>> Enter a positive integer:
>>> 9
>>> No, it is not a prime number
Sample input/output 2:
>>> Enter a positive integer:
>>> 13
>>> Yes, it is a prime number
This learning activity asks you to write a program.
Exercise 2. Greatest common divisor
The Greatest Common Divisor (GCD) is the greatest number that divides exactly two numbers. For example, the GCD for number 12 and 20 is 4. That is 4 is the largest number that can divides exactly both numbers. The GCD for 8 and 24 is 8, that is, 8 is the largest numbers that can both divide 8 and 24. The GCD for 14 and 15 is 1.
Write a Python program that allows the user to type in two numbers, one at a time, then calculate and output the GCD of both numbers.
Sample input/output:
>>> Enter the first number:
>>> 8
>>> Enter the second number:
>>> 12
>>> The GCD is 4
This learning activity asks you to write a program.
Exercise 3. Patterns
In this learning activity, you are going to write a program that outputs a similar pattern like the following:
*
**
***
****
*****
This pattern has five (5) line. On the 1st line, there is 1 asterial, 2nd line, 2 asterials, 3rd, 3 asterials, and so on and so forth. Write a Python program that allows user to type in a positive integer N. You will then generate a pattern that has N lines. For example, if the user type in 3, you will need to generate the following pattern:
*
**
***
If the user type in 10, you will then generate:
*
**
***
****
*****
******
*******
********
*********
**********
Attachment:- Programmign Exercises.rar