
hualnermorales
736 PointsTask 5 of 5: Multiply 5*5. I have clearly defined num1 but continue to get an error...
"Bummer: NameError: name 'num1' is not defined"
from flask import Flask
app = Flask(__name__)
@app.route('/multiply')
@app.route('/multiply/<int:num1>/<int:num2>')
@app.route('/multiply/<float:num1>/<int:num2>')
@app.route('/multiply/<int:num1>/<float:num2>')
@app.route('/multiply/<float:num1>/<float:num2>')
def multiply(num1=5,num2=5,product=num1*num2):
return '{} * {} = {}'.format(num1, num2, product)
3 Answers

hualnermorales
736 PointsGot the correct answer:
def multiply(num1 = 5, num2 = 5):
product = num1 * num2
return '{}'.format(product)

Anthony Crespo
Python Web Development Techdegree Student 12,960 PointsI don't think you can multiply local variable in there. (Maybe, I just don't know how?) If it's inside the function it works:
def multiply(num1=5,num2=5):
product = num1 * num2
return '{} * {} = {}'.format(num1, num2, product)
The way I understand it's that the arguments don't exist outside the scope of the body of the function cause if you use global variables it works:
a = 5
b = 5
def multiply(num1=5,num2=5, product = a * a):
return '{} * {} = {}'.format(num1, num2, product)

hualnermorales
736 PointsHey Anthony C., I think the question may be looking for something else because I'm still getting error messages...
'Bummer: Didn't get the expected response. Got 5 * 5 = 25.'
The quiz is telling us here that it doesn't want '5 * 5 = 25' as an answer. What solution could it be looking for?
def multiply(num1 = 5, num2 = 5):
product = num1 * num2
return '{} * {} = {}'.format(num1, num2, product)
Anthony Crespo
Python Web Development Techdegree Student 12,960 PointsAnthony Crespo
Python Web Development Techdegree Student 12,960 PointsOh yeah you right! It has to return only the product and not the whole mathematical formula. Sorry lol I corrected your code but didn't read the challenge.
You can even drop the product variable and make it shorter.
hualnermorales
736 Pointshualnermorales
736 PointsAnthony, thats pretty cool.
The lone 'f' allows you to perform a mathematical formula within the curly brackets I presume?
return f'{num1 * num2}'
Anthony Crespo
Python Web Development Techdegree Student 12,960 PointsAnthony Crespo
Python Web Development Techdegree Student 12,960 PointsIt's the new fstring (Python 3.6). It work the same as .format() but it's way shorter.