We are tasked stopping the program from printing negative numbers. How would I express that in Python? I don't need strings for every single converter. The program ideally would take note of the negative number. Then we have the program print a response and then terminate. MY PYTHON PROGRAM: #LAB 3 VERSION #Greeting the cousin and instructions. print( 'Hello cousin William! I have created a program  \ to convert my U.S.measurements to your metric system!') # A simple folllow up to the greeting explaining how the sequential statements will work. print( '\nSimply type in the measurement when prompted \ by the sequence of conversions.') #MILES TO KM CONVERSION miles = float(input("William, enter the number of miles you'd like to convert to kilometers: "))  #The miles are prompted from the user. kilometers = miles * 1.6 # This is the basic conversion of miles to kilometers print("William, according to my calculations: \n%.2f Miles equals %.2f Kilometers " %(miles, kilometers)) #The output printed to the nearest 2 decimal places. #FARENHEIT TO CELSIUS farenheit = float(input("William, enter the farenheit temperature you'd like to convert to celsius: " )) #The F temperature is prompted for. celsius = (farenheit - 32) * 5 / 9 #The conversion function arithmetic. print("William, here is the result for you: \n%.2f farenheit to %.2f celsius" %(farenheit, celsius)) #The result of the previous function with the units tacked on at the end. #GALLONS TO LITERS Gal = float(input("William, enter the number of gallons you'd like converted to liters: " )) Li = Gal * 3.9 print("William, no wonder gas is so expensive in Europe. Look at this conversion: \n%.2f Gal to %.2f Li " %(Gal, Li)) #Lbs to Kg Lbs = float(input("William, enter the number of pounds you'd like converted to kilograms: " )) Kg = Lbs * 0.45 print("William, it is so easy converting these units. Look at this one: \n%.2f Lbs to %.2f Kg " %(Lbs, Kg)) #In to cm In = float(input("William, enter the number of inches you'd like converted to centimeters: " )) cm = In * 2.54 print("Ending this short length program with a length conversion: \n%.2f In to %.2f cm " %(In, cm)) print( 'What do you think William? It is quite handy!') #print message to conclude the program. #The verbiage makes it messy and harder to read. I could've prompted more line skips, but I chose not to.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

We are tasked stopping the program from printing negative numbers.
How would I express that in Python?
I don't need strings for every single converter.

The program ideally would take note of the negative number.
Then we have the program print a response and then terminate.

MY PYTHON PROGRAM:

#LAB 3 VERSION

#Greeting the cousin and instructions.
print( 'Hello cousin William! I have created a program  \
to convert my U.S.measurements to your metric system!')
# A simple folllow up to the greeting explaining how the sequential statements will work.
print( '\nSimply type in the measurement when prompted \
by the sequence of conversions.')


#MILES TO KM CONVERSION
miles = float(input("William, enter the number of miles you'd like to convert to kilometers: "))  #The miles are prompted from the user.
kilometers = miles * 1.6 # This is the basic conversion of miles to kilometers
print("William, according to my calculations: \n%.2f Miles equals %.2f Kilometers " %(miles, kilometers)) #The output printed to the nearest 2 decimal places.

#FARENHEIT TO CELSIUS
farenheit = float(input("William, enter the farenheit temperature you'd like to convert to celsius: " )) #The F temperature is prompted for.
celsius = (farenheit - 32) * 5 / 9 #The conversion function arithmetic.
print("William, here is the result for you: \n%.2f farenheit to %.2f celsius" %(farenheit, celsius)) #The result of the previous function with the units tacked on at the end.

#GALLONS TO LITERS
Gal = float(input("William, enter the number of gallons you'd like converted to liters: " ))
Li = Gal * 3.9
print("William, no wonder gas is so expensive in Europe. Look at this conversion: \n%.2f Gal to %.2f Li " %(Gal, Li))

#Lbs to Kg
Lbs = float(input("William, enter the number of pounds you'd like converted to kilograms: " ))
Kg = Lbs * 0.45
print("William, it is so easy converting these units. Look at this one: \n%.2f Lbs to %.2f Kg " %(Lbs, Kg))

#In to cm
In = float(input("William, enter the number of inches you'd like converted to centimeters: " ))
cm = In * 2.54
print("Ending this short length program with a length conversion: \n%.2f In to %.2f cm " %(In, cm))

print( 'What do you think William? It is quite handy!') #print message to conclude the program.

#The verbiage makes it messy and harder to read. I could've prompted more line skips, but I chose not to.

 

Expert Solution
Step 1

To ensure that negative numbers are not printed on the screen.

 

In order to do that, we need to ensure that the programme does not input a negative number. If a negative value is entered, an error message should be displayed, and the programme must be terminated immediately.

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

I don't think you're understanding my dilemma.
I am not ALLOWED to use exit functions.
Yes, I know they work, but the professor said to NOT use them.
I'll be more clear again:
DO NOT use loops, functions, list, a menu etc…) In addition break, quit, exit, 
sys.exit, return, continue, or any other shortcut ion NEVER allowed.

 

The other thought I had was with def main function, but I AM NOT ALLOWED TO USE EXIT FUNCTIONS, otherwise this would be a very easy program.

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

The exit function still persists and does not logically exit. I don't understand.

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

My apologies, I did not specify enough.
I got the program to print the message when the values are negative, but it also prints the other messages.
I assume this has to do with the indentation. 

We are also no permitted to use EXIT functions.
We need to utilize: Boolean Logic, If, If-Else, If-Elif-Else Control Structure.


Would I utilize an if else statement like

PSEUDOCODE:

If value<0
              print(NO NEG NUMBERS ALLOWED)
else value>0
               then use the code I had previously?

I don't know how to make the program logically exit without exit functions.

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education