Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

whats wrong with my code? #Python3

+5 votes
asked Dec 13, 2020 by Fahim (230 points)

The code is not showing any output. 

import datetime

default_names = ["Justin", "John", "Emilee", "Jim", "Ron", "Sandra", "Veronica", "Whitny"]

default_amounts = [123.55, 94.23, 554.65, 353.4, 322.558441, 32.4, 99.99]

unf_message = """HI {name}!

Thank You for the purchase on {date}

We hope you are excidet about using it. 

Just as a reminder the purchase total was ${total}.

Have a great one! 

Team sales

"""

def make_messages(names, amounts):

messages = []

if len(names) == len(amounts):

i = 0

today = datetime.date.today()

txtTime = '{today.month}/{today.day}/{today.year}'.format(today=today)

for name in names:

new_amount = "%.2f" %(amounts[i])

new_message = unf_message.format(

name = name,

date = txtTime,

total = new_amount

)

i += 1

print(new_message)

make_messages(default_names, default_amounts)

3 Answers

+3 votes
answered Dec 16, 2020 by LiOS (6,420 points)
selected Dec 17, 2020 by Fahim
 
Best answer
The first issue is indentation, but I believe this is where you copied and pasted your code.

The second is the evalaution of the if condition. default_names array is 1 elements larger than default_amounts. Therefore, your if condition is false and exits.

The third is that I believe you are trying to re-iterate over the arrays outputting the message with each combination but there's an issue.
commented Dec 17, 2020 by Fahim (230 points)
Thanks. I forgot to make both lists the same size. that's the reason why its not working.

I am new to python and the code is from a tutorial.
+2 votes
answered Dec 15, 2020 by xDELLx (10,500 points)
Indentation is messed up, please post again using the "formatted" format in the editor.
commented Dec 17, 2020 by Fahim (230 points)
it's fixed now.
list size was not even there.
0 votes
answered Dec 17, 2020 by Caleb Tucker (140 points)
You never defined {Name} or {Date} or {Amount}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...