Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

It is a single question. Please solve it in Python. Thanks. The purpose of this question is to write a python program (script) that draws

image text in transcribed

image text in transcribed

It is a single question. Please solve it in Python. Thanks.

The purpose of this question is to write a python program (script) that draws a series of triangles. Write a function that begins with the header: def getposint (prompt): This function returns a positive integer if the user enters a positive. The function repeatedly asks for a positive integer until the user enters either a positive. Hint: Strip the leading and trailing whitespace from the input from the user. If value is the value returned by input the function must perform the following tests: - if value is not an integer display value of value and the message 'is not an integer!'. - if value is an integer but is less than zero display value of value and the message 'is not a positive integer!'. - if eval (value, {,{}) causes an exception display the message 'Invalid input!'. - if value is an empty string (that is the user did not type anything in and pressed return/enter) display the message 'Missing input!' Note: You should be able to modify an example given in class to do this. Write a function that begins with the header: The function is given the size of a triangle to draw. The size must be a positive integer. For example if size is 3 the output should be *** and if size is 5 the output should be * kk Write a function that begins with the header: This function repeatedly calls getPosint in a loop. If the value returned by getPosInt is 0 exit from the loop, otherwise call drawTriangle with the value returned by getPosint. The main program (not to be confused with the function main) should contain any import statements needed, the definitions of the functions and the statement main 0 . Sample output from the program is given below: Enter the size of the triangle ( 0 to end): 4 Draw a triangle whose size is 4 . Enter the size of the triangle (0 to end): Missing input! Enter the size of the triangle (0 to end): 1.5 1.5 is not an integer! Enter the size of the triangle (0 to end): -1 1 is not a positive integer! Enter the size of the triangle (0 to end): True True is not an integer! Enter the size of the triangle (0 to end): 'hi' hi is not an integer! Enter the size of the triangle (0 to end): junk Invalid input! Enter the size of the triangle ( 0 to end): 3 Draw a triangle whose size is 3 . Enter the size of the triangle ( 0 to end): 0 Programmed by Stew Dent. Date: Thu Jun 7 10:20:21 2018

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions

Question

Is what I want clear?

Answered: 1 week ago

Question

5. Our efficiency focus eliminates free time for fresh thinking.

Answered: 1 week ago