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

  Create a stop word list made up of the words

Write a script or application that takes a start page as a command line parameter - Create a stop word list made up of the words that appear in every document

  Student record due smartsite thursday 1211 1155 pm file

due smartsite thursday 1211 1155 p.m. file names grading.py ltbrgtall prompts for input and all output must match my

  Describe your analysis in terms of general n

Write a function, largest_34(a), that returns the sum of the 3rd and 4th largest values in the list a. write your analysis in terms of general n.

  Create the pseudo code from the following request

The program must have some sort of menu that allows users to make selections to do a particular calculation. It must provide five menu items that allow the user

  How when you are typing a text message

You have all experienced how when you are typing a text message the application will provide potential words that complete what you are typing (and sometimes insist on completing them incorrectly).

  Server application that accepts connections

A client application that takes user input and for each input value creates a message object, generates hash-codes for it, then connects and sends object

  Calculates a new value based on an original value

Write a program that calculates a new value based on an original value and a (percentage-like) increase or decrease - You can store the results to be printed

  Prompt for the rate of return on an investment and calculate

Write a quick calculator that prompts for the rate of return on an investment and calculates how many years it will take to double your investment.

  Write a simple python program

Write a simple python program that takes use inputs as non-zero digits and converts them into binary form. The response must be typed.

  Show summary information about an event

Developing will be used by event organizers staff who are promoting social gatherings. e.g. LAN Parties, Board - Create customer details - Name, Email

  Write program that allows user to enter the total rainfall

Write a program that allows the user to enter the total rainfall for each of 12 months into an array. Calculate the total rainfall for the year

  Write a program that calculates the volume of a cylinder

Write a program that calculates the volume of a cylinder. Your program should ask the user to enter the radius and the height of the cylinder.

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