Python Chapter4 Solutions.py
Python Chapter4 Solutions.py
#3 Temperatures
temp = eval(input('Enter a temperature: '))
if temp <= 0:
print('Warning: Low temperature.')
elif 0 < temp < 35:
print('Temperature is okay.')
else:
print('Warning: High temperature.')
#4 Days in a month
days = eval(input('Enter number of days: '))
if days == 28 or days == 29:
print('Feb')
elif days == 30:
print('Apr, Jun, Sep, Nov')
elif days == 31:
print('Jan, Mar, May, Jul, Aug, Oct, Dec')
else:
print('Error')
#5 Feet conversion
feet = eval(input('Enter a length in feet: '))
unit = input('Enter unit to convert to (inches, centimeters, or meters): ')
if unit == 'inches':
print('In inches, that is', feet*12)
elif unit == 'centimeters':
print('In centimeters, that is', feet*30.48)
elif unit == 'meters':
print('In meters, that is', feet*.3048)
else:
print('Not a valid unit.')
#6 Spanish numbers
num = eval(input('Enter a number from 20 through 99: '))
if 20 <= num < 30:
print('veinte')
elif 30 <= num < 40:
print('treinta')
elif 40 <= num < 50:
print('cuarenta')
elif 50 <= num < 60:
print('cincuenta')
elif 60 <= num < 70:
print('sestenta')
elif 70 <= num < 80:
print('setenta')
elif 80 <= num < 90:
print('ochenta')
elif 90 <= num <= 99:
print('noventa')
else:
print('Number needs to be from 20 to 99.')
#8 Divisibility by 7
num = eval(input('Enter a number: '))
if num % 7 == 0:
print('It is divisible by 7.')
else:
print('Not divisible by 7.')