Question

In: Computer Science

Objectives:         The objectives of this lab exercise are to: Demonstrate an understanding of the concept...

Objectives:

        The objectives of this lab exercise are to:

  1. Demonstrate an understanding of the concept of operator precedence in Python expressions and statements.
  2. Take simple problem descriptions and produce small but complete Python programs that solve these problems.
  3. Give you some practice in using simple Python interactive input and output capabilities.
  4. Give you some practice in the simplest Python decision statement (if).
  5. Give you some practice in the simplest Python loop statement (while).

Specifications:

This is a four-part exercise.

  1. For the three assignment statements listed below, label the operators according to the order they will be evaluated, i.e., label the first evaluated operator with a 1, the second with a 2, and so on.   Then fill in the blank with the result assigned to variable x in each part.

                        i.    x = 7 + 3 * 6 / 2 – 1                                                                                                                       

                                 x = ________

                        ii.   x = 2 % 2 + 2 * 2 – 2 / 2                                                                                                                            

                                 x = ________

                        iii.   x = ( 3 * 9 * ( 3 + ( 9 * 3 / 3 ) ) )                                                                                                    

                                 x = ________

  1. Write a Python program that inputs three (3) integers to IDLE from the keyboard and prints the sum, average, product, smallest and largest of these numbers. For this exercise you may assume the user does NOT enter any duplicate values. The interactive screen dialogue should look something like this (user input is shown in bold):

Input three different integers separated by <enters>:

13

27

14

                                   

                                    Sum is 54

                                    Average is 18

                                    Product is 4914

                                    Smallest is 13

                                    Largest is 27

  1. Write a Python program in IDLE that asks for the radius of a circle and prints the circle’s diameter, circumference, and area. Import the math library for p. Do the calculations for diameter, circumference and area in the output statements. You do NOT need variables for holding your calculated values of diameter, circumference, or area. Just place the appropriate expression as an argument to the print() function.
  1. Write a Python program in IDLE that asks for an integer and determines and prints whether it is odd or even. (Hint: Use the modulus operator (%). An even number is a multiple of 2 and any multiple of 2 leaves a remainder of zero (0) when divided by 2).

Discussion:

In addition to the documentation requirements specified in lab 1, first write the entire program in pseudocode as comments. When necessary place a comment to the right of complicated lines to clarify your code to the reader. Further, comments should not merely repeat what is obvious from a program statement. For example, avoid what follows. This statement below adds nothing to understanding what the statement does or what its purpose is within the program:

                        Sum = Sum + 1   # Add 1 to Sum ß A totally worthless comment!

Deliverable(s):

Your deliverable should be a Word document with screenshots showing the sample code you have created, and discuss the issues that you had for this project related to AWS and/or Python IDE and how you solved them.

Turn in your source code listings for the programs developed above. Include screen shots of the results from running the programs you developed for three (3) sets of test data (for each program). Choose your test cases carefully so they reflect good values to test all aspects of your solutions.

Solutions

Expert Solution

i.    x = 7 + 3 * 6 / 2 –

1-3*6 // As multiply and division operator has the same priority so we take which operator appears in left so multiply operator will evaluate first

2-18/2

3-9+7

4 -

if - is there then it is a syntax error

without - symbol at last x value will be 16.0

ii.   x = 2 % 2 + 2 * 2 – 2 /

1- 2%2

2- 2*2

3- 0+4

4- 4-2

5 -/

if / is there then it is a syntax error

without / symbol at last x value will be 2

iii.   x = ( 3 * 9 * ( 3 + ( 9 * 3 / 3 ) ) )

1 - 9*3

2 - 27/3

3- 3 +9

4- 12*9

5- 108*3

x=324   

Write a Python program that inputs three (3) integers to IDLE from the keyboard and prints the sum, average, product, smallest and largest of these numbers

Code with comments

first_number=int(input())#To get input for first number
second_number=int(input())#To get input for second number
third_number=int(input())#To get input for third number

sums=first_number+second_number+third_number# calculates the sum
average=sums//3# calculates the average
product=first_number*second_number*third_number
if (first_number <= second_number) and (first_number <= third_number):# To check first number is minimum
minimum = first_number
elif (second_number <= first_number) and (second_number <= third_number):# To check second number is minimum
minimum = second_number
else:
minimum=third_number
if (first_number >= second_number) and (first_number >= third_number):# To check first number is maximum
maximum = first_number
elif (second_number >= first_number) and (second_number >= third_number):# To check second number is maximum
maximum = second_number
else:
maximum=third_number
print("Sum is ",sums)
print("Average is ",average)
print("Product is ",product)
print("Smallest is ",minimum)
print("Largest is ",maximum)
Output ScreenShot

Write a Python program in IDLE that asks for the radius of a circle and prints the circle’s diameter, circumference, and area. Import the math library for p. Do the calculations for diameter, circumference and area in the output statements. You do NOT need variables for holding your calculated values of diameter, circumference, or area. Just place the appropriate expression as an argument to the print() function.

Code

import math
radius = input("Enter radius of circle: ");# gets the radius of the circle as input from the user
radius =float(radius);# coverts the radius value to float for better calcullation
diameter=2*radius# to calcualate diameter
area=math.pi*radius*radius# to calculate area
circumference = 2*math.pi*radius;# to calculate circumference
print("\nDiameter of Circle =",diameter);
print("\nArea of Circle =",area);
print("\nCircumference of Circle =",circumference);

Cose output Screen Shot

Write a Python program in IDLE that asks for an integer and determines and prints whether it is odd or even. (Hint: Use the modulus operator (%). An even number is a multiple of 2 and any multiple of 2 leaves a remainder of zero (0) when divided by 2).

Code:

x=int(input("enter the number to be checked even or odd"))# gets a integer as input
if x%2==0:# check ithe integer is even using the hint provided
print("even")
else:
print("odd")

OUTPUT SCREEN SHOT



Related Solutions

The goal of this exercise is to demonstrate your understanding of the characteristics that influence the...
The goal of this exercise is to demonstrate your understanding of the characteristics that influence the choice of business ownership formation. RT Taxes: After years of preparing taxes for his extended family, Ronald began a tax consultant business from his home office. He hires assistants as needed but does all of the management and main services himself. Pet Perfect: John with an expertise in sales, and Francine, with an expertise in management, opened a pet shop together, sharing profits and...
How Much Iron is in Total Cereal?        The following at home lab exercise will demonstrate...
How Much Iron is in Total Cereal?        The following at home lab exercise will demonstrate that iron is actually in iron fortified cereal such as Total.        Materials: 1 cup iron fortified cereal (Total) 2 cups of hot water (from the sink)   1 clear glass large enough to hold the cereal and the water. Magnet- The magnet can be from an inexpensive refrigerator magnet. You will be able to see the results better if you paint the magnet white...
Using examples, demonstrate your understanding of the concept of ‘risk management’ in financial markets contexts. How...
Using examples, demonstrate your understanding of the concept of ‘risk management’ in financial markets contexts. How can options be used to manage risk?
Demonstrate an understanding of the product development process?
Demonstrate an understanding of the product development process?
Demonstrate an understanding of the reporting requirements and auditing standards.
Demonstrate an understanding of the reporting requirements and auditing standards.
Understanding the basis of infection is essential when working in a healthcare environment. Demonstrate your understanding...
Understanding the basis of infection is essential when working in a healthcare environment. Demonstrate your understanding of the following terminology (in 20-40 words each) Terminology a. Colonisation b. Infection c. Disease
Description The purpose of this assignment is to demonstrate understanding of basic alterations in vision and...
Description The purpose of this assignment is to demonstrate understanding of basic alterations in vision and hearing. Compose a short (1.5 – 2.5 page) essay explaining one common alteration in vision and one common alteration in hearing. You should briefly describe the pathophysiologic changes, prevalence, manifestations, and treatment for each. You should also explain the mechanism that the specific treatment uses to return a normal functioning state. You may select a disease process from the book, but will need to...
Demonstrate an understanding of the purpose of an outreach program along with services that could be...
Demonstrate an understanding of the purpose of an outreach program along with services that could be provided. What are the potential types of outreach programs that could be implemented? How do the various strategies for implementing an outreach program impact the quality of testing?
Use this assessment as an opportunity to demonstrate the breadth of your knowledge and understanding of...
Use this assessment as an opportunity to demonstrate the breadth of your knowledge and understanding of experimental design.Respond to the following question in essay format. Approximately, three to four paragraphs or 500-550 words. G. has just completed a study that shows a correlation between the amount of time children watch television and their attention spans. Assume the correlation was r = -.34. State an experimental hypothesis based on this finding and devise a simple procedure for testing it.
Select an organization in your area and identify three of their objectives, and then demonstrate how...
Select an organization in your area and identify three of their objectives, and then demonstrate how maintenance can contribute to achieving them.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT