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.

what is wrong

4 Answers

0 votes
answered Mar 3 by לויט יהודה רובי (460 points)
my guess.

on line 6 you wrote:

     amount_of_time-=1

you didn't define "amount_of_time" as a start.

therefor you can't take of it's value by one.
0 votes
answered Mar 3 by Peter Minarik (63,560 points)

If you look at the error message, you'll see what's wrong:

NameError: name 'amount_of_time' is not defined

And another error message, if you'd fix the above one:

NameError: name 'gift' is not defined

Both of these variables exist only within the timer() function, so trying to access them in the birthday() function is not going to work.

I'm not sure what you're trying to achieve in your code. Maybe you can tell in a few sentences what it's supposed to do and then it would be easier to find a proper fix for your code.

0 votes
answered Mar 3 by Kokoz (300 points)

One more thing- I see you import time and use the sleep function, but you need to write it like that: time.sleep(1)
Otherwise it doesn't recognize it as a function..
As Peter said, give us some more context so we can help..

0 votes
answered Apr 2 by userdotexe (1,340 points)

Possibly globalizing the variables will help:

import time

global amount_of_time

global gift
Sam=dict(age=10, birthday="March 23rd", real_name="Samuel", nickname="Sam")
def timer (amount_of_time,gift):
    while amount_of_time!=0 and gift!="":
        sleep (1)
        amount_of_time-=1
    return amount_of_time
def birthday ():
    Sam["age"]+=1
    print (f"It's your birthday Sam! You are now {Sam['age']} years old! I got you {gift} for a present" if amount_of_time!=0 else "oh no you ran out of time")
birthday()

:)

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.
...