Question

In: Computer Science

PYTHON Program Problem Statement: Write a Python program that processes information related to a rectangle and...

PYTHON Program

Problem Statement: Write a Python program that processes information related to a rectangle and prints/displays the computed values.

The program will behave as in the following example. Note that in the two lines, Enter length and Enter width, the program does not display 10.0 or 8.0. They are values typed in by the user and read in by the program. The first two lines are text displayed by the program informing the user what the program does.

This program reads in the length and width of a rectangle. It then prints the area and perimeter of the rectangle.

Enter length: 10.0
Enter width: 8.0

Length 10.0 width 8.0 area 80.0 perimeter 36.0

  1. Create two pieces of data (other than what we have above) that would serve as input to the program; then write down what the output would be. We show a sample first. (We are ignoring here the first two lines of text that would always be displayed.)

    Sample Input 0: Length 20 width 5
    Expected Output for the above data
    Length 20.0 width 5.0 area 100.0 perimeter 50.0

    Create your own data now.

    Input 1: length width Expected Output for the above data

    Input 2: length width Expected Output for the above data

  2. Before proceeding, get OK from your instructor or the tutor.

  3. Using the Input-Processing-Output approach, write down the pseudo code for the program.

  1. Before proceeding, get OK from your instructor or the tutor.

  2. Convert the pseudo code to Python code. Use ideas from below.

Pseudo code

Input an integer into x
Input a number with a decimal point into x Set x to a + b
Set x to a * b
Print a, b, c
Print weight and mass annotated
Print a message

Python code

x = int(input(‘Enter a number: ‘))
x = float(input(‘Enter a number: ‘))
x = a + b
x = a * b
print(a, b, c)
print(‘weight is’, weight, ‘mass is’, mass) print(‘whatever message you want’)

  1. Test and debug the program. For testing, use the data you created in Step 1.

  2. Show your source program and demonstrate it to your instructor. Get his/her signature below.

Solutions

Expert Solution

Pseudo code

Input an integer into length
Input an integer into width
set area to length * width
set perimeter to 2*(length+width)
print length width area perimeter annotated

PYTHON CODE:

# getting input length from the user
length=float(input("Enter length: "))

# getting input width from the user
width=float(input("Enter width: "))

# calculating the area of the rectangle
area= length * width

# calculating the perimeter of the rectangle
perimeter=2 * (length+ width)

# printing length, width, area, perimeter
print("Length %.1f width %.1f area %.1f perimeter %.1f" %(length,width,area,perimeter))


SCREENSHOT FOR CODING:

SCREENSHOT FOR OUTPUT:


Related Solutions

Program in Python Problem Statement Write a program with the following functions:  wordCount. This function...
Program in Python Problem Statement Write a program with the following functions:  wordCount. This function should accept a string as a parameter and return the number of words contained in the string.  mostFrequentWord. This function accepts a string as a parameter and returns the word that occurs the most frequently in the string.  replaceWord. This function accepts three strings as parameters, let’s call them string1, string2, and string3. It searches string1 for all occurrences of string2. When...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a...
Write a Python program which uses a function to calculate the perimeter of a rectangle. a function named volume to calculate the volume of a cylinder volume = 3.14 x radius x radius x height .b function named volume to calculate the volume of a cuboid volume = Length x width x ht Write a Python Program to calculate the sum of all odd numbers for 2 to 20 using a for loop. 4. Write statements that assign random integers...
Python Problem Problem 1: In this problem you are asked to write a Python program to...
Python Problem Problem 1: In this problem you are asked to write a Python program to find the greatest and smallest elements in the list. The user gives the size of the list and its elements (positive and negative integers) as the input. Sample Output: Enter size of the list: 7 Enter element: 2 Enter element: 3 Enter element: 4 Enter element: 6 Enter element: 8 Enter element: 10 Enter element: 12 Greatest element in the list is: 12 Smallest...
Write a complete and syntactically correct Python program to solve the following problem: Write a program...
Write a complete and syntactically correct Python program to solve the following problem: Write a program for your professor that allows him to keep a record of the students’ average grade in his class. The program must be written in accordance with the following specs: 1. The input must be interactive from the keyboard. You will take input for 12 students. 2. You will input the students’ name and an average grade. The student cannot enter an average below zero...
Please write simple python program with explanation Problem statement: Stock markets are venues where buyers and...
Please write simple python program with explanation Problem statement: Stock markets are venues where buyers and sellers of shares meet and decide on a price to trade.Eddard is very interested in trading in stock market and he started gathering information of one stock.He has projected market prices for that share over the next n months.Eddard wants to purchase and resell the share to earn profits.He is much worried about the loss that might occur so he wanted to calculate "Minimum...
Write a Python program that represents various geometric shapes. Each shape like rectangle, square, circle, and...
Write a Python program that represents various geometric shapes. Each shape like rectangle, square, circle, and pentagon, has some common properties, ex. whether it is filled or not, the color of the shape, and number of sides. Some properties like the area of the shapes are determined differently, for example, area of the rectangle is length * widthand area of a circle is ??2. Create the base class and subclasses to represent the shapes. Create a separate test module where...
Write a Python program that represents various geometric shapes. Each shape like rectangle, square, circle, and...
Write a Python program that represents various geometric shapes. Each shape like rectangle, square, circle, and pentagon, has some common properties, ex. whether it is filled or not, the color of the shape, and number of sides. Some properties like the area of the shapes are determined differently, for example, area of the rectangle is length * widthand area of a circle is ??2. Create the base class and subclasses to represent the shapes. Create a separate test module where...
Rectangle Information. This program displays information about a rectangle drawn by the user. Input: Two mouse...
Rectangle Information. This program displays information about a rectangle drawn by the user. Input: Two mouse clicks for the opposite comers of a rectangle. Output: Draw the rectangle. Print the perimeter and area of the rectangle. Formulas: area = (length)(width) perimeter = 2(length + width)
Write a program 'Rectangle-Area.c' that inputs the length and width of a rectangle and outputs its...
Write a program 'Rectangle-Area.c' that inputs the length and width of a rectangle and outputs its area. The program consists of two functions: the main function and a function that computes and returns the area of a rectangle. The output of the program should be in the main program, not in the function.      Sample Input: 5 8   Sample Output: The area of a 5 by 8 rectangle is 40.
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT