English 中文(简体)
在全球变数条件下在功能之外的收益
原标题:return outside of function with a global variable
  • 时间:2024-03-24 02:26:00
  •  标签:
  • python

For my code an assignment is requesting "a return statement returns to the statement in the main() function that is after the call to the play game() function".

I tried entering the return statement after the rand variable and received the error return outside of function. I would like to understand the correct way to use the return statement to complete the assignment

def play_game():
  return
  global rand
  rand=random.randint(1,10)
  play_game()
问题回答

a 返回声明在要求游戏功能后的主要()功能中恢复声明

请注意,这是解释,而不是请求。 如果你的问题是这一解释的含义,我们就可以打破这一解释。

首先,需要<代码>main():

def main():
    pass

Second of all, it says that the main() function should call the play_game() function:

def play_game():
    pass

def main():
    play_game()

Next, the play_game() function needs a return statement:

def play_game():
    return

def main():
    play_game()

你们往往从一项职能中收回价值,但你在这里没有给我足够的信息来猜测应该做些什么,因此,我仅举一个光彩的<条码>。

Finally, the main() function needs something after the play_game() function. We ll just add a print() statement. While we are add it, we will add a print() to play_game() to understand how things work:

def play_game():
    print("Playing game...")
    return

def main():
    print("Starting...")
    play_game()
    print("Finishing.")

如果你执行这一短期方案,你将把产出视为产出。

Starting...
Playing game...
Finishing.

参看<代码>return。 要求在<代码>_me(>后继续实施main(>>。

I hope this helps.

页: 1 如果你需要更多的帮助,请将问题带上更多的细节,帮助我们了解你 where的处处。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签