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

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...
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...
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...
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...
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 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,...
use Python datetime module, strftime Write a program that processes the following textfile and prints the...
use Python datetime module, strftime Write a program that processes the following textfile and prints the report shown below. Textfile: Ask the user for the filename and BE SURE TO CHECK THAT IT EXISTS. The file will contain lines which each contain 2 strings (bookTitle and publicationDate) separated by a comma and a space. Note that the title of the book might contain spaces! Example of the textfile: Gone Girl, 5-24-2012 To Kill A Mockingbird, 7-11-1960 Harry Potter and the...
Write a program that asks the user for the lengths of the sides of a rectangle....
Write a program that asks the user for the lengths of the sides of a rectangle. Again, check for valid input and exit with an error msg if you don’t get it. Testing: use some known values to confirm that the calculations are correct. E.g. 3 – 4 - 5 triangle >> 3 X 4 rectangle Then print • The area and perimeter of the rectangle • The length of the diagonal (use the Pythagorean theorem). This question should be...
Write a complete and syntactically correct Python program to solve the following problem: You are the...
Write a complete and syntactically correct Python program to solve the following problem: You are the payroll manager for SoftwarePirates Inc. You have been charged with writing a package that calculates the monthly paycheck for the salespeople. Salespeople at SoftwarePirates get paid a base salary of $2000 per month. Beyond the base salary, each salesperson earns commission on the following scale: Sales Commission Rate Bonus <$10000 0% 0 $10000 – $100,000 2% 0 $100,001 - $500,000 15% $1000 $500,001 -...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT