Fer said:
diveintopython3.org is DOWN
Exercise 4.4
Answer is B, exactly it's the start of a function DEFINITION
C could be taken as right since you define a function to be used later on. so D would be right then
Exercise 4.5
The right would be
ABC
Zap
ABC
So the closest answer is D
Exercise 4.6
# -*- coding: iso-8859-15 -*-
horas = int(raw_input("Enter hours:"))
precio = float(raw_input("Precio / hora"))
def paga(horas, precio):
if horas > 40:
extra = horas - 40
payment = (40 * precio) + ((extra * precio) * 1.5)
else:
payment = horas * precio
return payment
print paga(horas, precio)
Exercise 4.7
# -*- coding: iso-8859-15 -*-
nota = raw_input("Introduce nota ")
def grado(nota):
if nota > 1 or nota < 0:
grade = 'None'
elif nota >= 0.9 :
grade = 'A'
elif nota >= 0.8 :
grade = 'B'
elif nota >= 0.7 :
grade = 'C'
elif nota >=0.6 :
grade = 'D'
else :
grade = 'F'
return grade
try:
nota = float(nota)
print "El grado es "+grado(nota)
except:
print "solo numeros!"