In: Computer Science
Question Objectives: The objectives of this lab exercise are to: Demonstrate an understanding of the concept of operator precedence in Python expressions and statements. Take simple problem descriptions and produce small but complete Python programs that solve these problems. Give you some practice in using simple Python interactive input and output capabilities. Give you some practice in the simplest Python decision statement (if). Give you some practice in the simplest Python loop statement (while). Specifications: This is a four-part exercise. 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 = ________ 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 : 13 27 14 Sum is 54 Average is 18 Product is 4914 Smallest is 13 Largest is 27 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. 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.
x = 7 + 3 * 6 / 2 - 1
3 * 6 -> 1st
18 / 2 -> 2nd
7 + 9 -> 3rd
16 - 1 ->4th
final result x = 15
x = 2 % 2 + 2 * 2 – 2 / 2
2 % 2 -> 1st
2 * 2 ->2nd
2 / 2 ->3rd
0 + 4 -> 4th
4 - 1 -> 5th
final result x = 3
x = ( 3 * 9 * ( 3 + ( 9 * 3 / 3 ) ) )
(9 * 3 / 3) -> 1st
9 * 3 -> 2nd
(27 / 3) -> 3rd
(3 + 9) ->4th
3 * 9 ->5th
27 * 12 -> 6th
final value x = 324
#prompting the three number as input from the user
a = int(input("enter the first number:"))
b = int(input("enter the second number:"))
c = int(input("enter the third number:"))
#finding the greatest of the three using if condition
def greater(a, b, c):
if(a > b and a > c):
return a
elif(b > a and b > c):
return b
elif(c > a and c > b):
return c
else:
return 0
#finding the smallest of the three using if conditions
def smaller(a, b, c):
if(a < b and a < c):
return a
elif(b < a and b < c):
return b
elif(c < a and c < b):
return c
else:
return 0
#finding the sum of the three
def sum_all(a, b, c):
total = a + b + c
return total
#finding the average of the three
def Average(a, b, c):
return sum_all(a, b, c) / 3
print("{} {} {} Sum is {} Average is {} smaller is {} greater is {}".format(a, b, c, sum_all(a, b, c), Average(a, b, c),smaller(a, b, c), greater(a, b, c)))
If you have any doubts please comment and please don't dislike.