In: Computer Science
Objectives:
The objectives of this lab exercise are to:
Specifications:
This is a four-part exercise.
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 = ________
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
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.
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