Programming exercise - prime number

Assignment Help Python Programming
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

Reference no: EM133059361

Questions Cloud

Programming exercise - tayler expansion : Programming Exercise - Tayler expansion - how to determine whether a particular number is a prime number. In this learning activity
What is the contribution margin per unit and ratio : The accountant has provided Tupac with the following data to prepare next year's campaign. What is the contribution margin per unit and ratio for 2022
Calculate the payback period of the new machine : The net cost of this machine is $250,000 and is expected to have a useful life of 5 years, Calculate the payback period of the new machine
Calculate the change in operating profit due to productivity : Factory support costs do not vary with the actual number of motors made that year. Calculate the change in operating profit due to productivity
Programming exercise - prime number : Programming Exercise - Prime number - write a Python program that determines whether a user's input is a prime number or not
How much would Ramiro adjust its investment in Marco Company : Marco reported net income of $74,200 and declared dividends of $20,300 during the year. How much would Ramiro adjust its investment in Marco Company
What would be an approximate market price per share : If the common stock had a market price of $140 per share before the stock split, what would be an approximate market price per share after the split
Briefly define the term accountability : Briefly define the term accountability and explain why the notion of social and environmental accountability is a greater focus of accounting today
What is the value of HBB Company : HBB Company for the last ten years, has earned and had cash flows of about Php 500,000 every year. What is the value of HBB Company

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd