Question

In: Computer Science

Python: I want to make the following code to prompt the user if want to run...

Python: I want to make the following code to prompt the user if want to run the software again. I am new to python, so i do not know if it works like c++. If can explain that would be much appreciated

base = float(input("Enter base of the triagle: "))

Triangle_Right = float(input("Enter right side of the triagle: "))

Triangle_Left = float(input("Enter left side of the triagle: "))

height = float(input("Enter the height of the triangle: "))

perimiter = base + Triangle_Right + Triangle_Left

area = (base*height)/2

print("The perimiter is =", perimiter)

print("The area is =", area)


Solutions

Expert Solution

# read a base value for triangle and store it in variable base as a float(same as c++ float)
base = float(input("Enter base of the triangle: "))
# read a right side value for triangle and store it in variable Triangle_Right as a float(same as c++ float)
Triangle_Right = float(input("Enter right side of the triangle: "))
# read a left side value for triangle and store it in variable Triangle_Left as a float(same as c++ float)
Triangle_Left = float(input("Enter left side of the triangle: "))
# read a height value for triangle and store it in variable height as a float(same as c++ float)
height = float(input("Enter the height of the triangle: "))
# calculate perimeter
perimeter = base + Triangle_Right + Triangle_Left
# calculate are
area = (base * height) / 2
# print perimeter
print("The perimeter is =", perimeter)
# print area
print("The area is =", area)

"""
This is mostly like C++
don't need to use ; after each statement
print is used like cout
and input is used instead of cin
all other statements are mostly same
"""


Related Solutions

code in python I want to make a function that adds all the multipliers together. The...
code in python I want to make a function that adds all the multipliers together. The code is posted below and please look at wanted output section to see what I want the code to output. The last line of the code is the only addition I need. Thanks. Code: initial=int(input("Initial value : "))       #taking inputs multiplier=float(input("Multiplier : ")) compound=int(input("No of compounds : ")) print("Your values are:") mult=initial                         #initalizing to find answer for i in range(0,compound):         #multiplying by multiplier    ...
Python Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
lets say i make a PYTHON code that lets a user guess a number between 1-1000,...
lets say i make a PYTHON code that lets a user guess a number between 1-1000, every failed attempt you get a hint (go lower or go higher) how can i penalize the user if they dont follow the hints, example ( go higher!... your next pick: a smaller number... 2 you loose $100 for not following hint) 2 and the user has unlimited attempts, until he guesses the number, this is made using random.randint(1,1000) function THE ONLY THING IM...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
what is the solution of this code? Also how would I run it in python to...
what is the solution of this code? Also how would I run it in python to check? q = Queue() q.enqueue(10) q.enqueue(12) q.enqueue(15) for i in range(len(q)): → if len(q) % 2 == 0: → → q.enqueue(q.dequeue()) → else: → → q.dequeue() print(q)
In Python, your program will read in a number (no need to prompt the user), and...
In Python, your program will read in a number (no need to prompt the user), and then reads in that number of lines from the terminal. Then the program should print an array of strings formatted in a nice regular box. So if the user inputs this: 5 Grim visaged war has smooth’d his wrinkled front And now, instead of mounting barded steeds To fright the souls of fearful adversaries He capers nimbly in a lady’s chamber To the lascivious...
This code needs to be in C++, please. Step 1: Add code to prompt the user...
This code needs to be in C++, please. Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code...
Could you modify my code so it meets the following requirement? (Python Flask) I want the...
Could you modify my code so it meets the following requirement? (Python Flask) I want the user to register for account using email and password, then store that data into a text file. Then I want the data to be read when logging in allowing the user to go to home page. -------------Code-------------------- routes.py from flask import Flask, render_template, redirect, url_for, request, session import json, re app = Flask(__name__) '''@app.before_request def before_request(): if 'visited' not in session: return render_template("login.html") else:...
*******************In Python please******************* (1) Prompt the user to enter a string of their choosing. Store the...
*******************In Python please******************* (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be more shuttle flights and more...
run in python IDLE 3.9.0 i) One that prompts a user for 2 numbers. ii) Adds...
run in python IDLE 3.9.0 i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are even iii) Multiplies the two numbers if they are odd iv) Displays the appropriate output to the user You are writing 4 functions and calling them to test functionality.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT