PYTHON PROGRAMMING EXERCISES WITH ANSWERS

BOOK TITLE:
A Practical Introduction to Python Programming


Chapter 4
If statements


EXERCISE AND SOLUTION


"""
Write a program that asks the user to enter a length in centimeters.
If the user enters a negative length, the program should tell the user that the entry is invalid.
Otherwise, the program should convert the length to inches and print out the result.
There are 2.54 centimeters in an %% inch.
"""

"""//

T=eval(input('Enter the length in cm: '))
L= T/2.54
if T<0: font="">
    print('The length is invalid.')
elif T>0:
    print('The length in inches is: ', L)

//"""

"""
Ask the user for a temperature. Then ask them what units, Celsius or Fahrenheit, the temperature
is in. Your program should convert the temperature to the other unit. The conversions
are F =9/5(C+32) and C =5/9(F-32).

"""

"""//

T = eval(input('Enter the Temperature: '))
L = input('The input temperature units are F or C: ')

F=9/5*T+32
C=(5/9)*(T-32)

if (L=='C'):
    print('The temperature in F is:', F)
elif (L=='F'):
    print('The temperature in C is:', C)


//"""

"""

Ask the user to enter a temperature in Celsius. The program should print a message based
on the temperature:

If the temperature is less than -273.15, print that the temperature is invalid because it is
below absolute zero.

If it is exactly -273.15, print that the temperature is absolute 0.
If the temperature is between -273.15 and 0, print that the temperature is below freezing.
If it is 0, print that the temperature is at the freezing point.
If it is between 0 and 100, print that the temperature is in the normal range.
If it is 100, print that the temperature is at the boiling point.
If it is above 100, print that the temperature is above the boiling point.


"""

"""//

T=eval(input('Enter the temperature in Celcius: '))

if T==-273.15:
    print('The temperature is absolute 0')
elif T<=-1:
    print('The temperature is below freezing')
elif T==0:
    print('The temperature is at freezing point')
elif T<100: font="">
    print('The temperature is in normal range')
elif T==100:
    print('The temperature is at boiling point')
else :
    print('The temperature is above boiling point')

//"""


Comments

  1. I'm Абрам Александр a businessman who was able to revive his dying lumbering business through the help of a God sent lender known as Benjamin Lee the Loan Consultant. Am resident at Yekaterinburg Екатеринбург. Well are you trying to start a business, settle your debt, expand your existing one, need money to purchase supplies. Have you been having problem trying to secure a Good Credit Facility, I want you to know that Mr Benjamin will see you through. Is the right place for you to resolve all your financial problem because am a living testimony and i can't just keep this to myself when others are looking for a way to be financially lifted.. I want you all to contact this God sent lender using the details as stated in other to be a partaker of this great opportunity Email: lfdsloans@outlook.com  Or  WhatsApp/Text +1-989-394-3740.

    ReplyDelete

Post a Comment

Popular posts from this blog

Learning to Use Arduino with Proteus (Programming of LCD)

Roboguide Simulation