Why do I get an error name play is not defined when I think it is?

2024/10/9 10:22:12

Full error:

line 10, in <module>colour = play()
NameError: name 'play' is not defined

I can't seem to find a reason for this issue anywhere on here. I am trying to assign the returned string to the variable colour but it is refusing to recognise the function "play".

import random
Funds = 10
Bet = "Red"
betsequence = [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
counter = -1
totalcount = 0while(Funds > 0):counter = counter + 1colour = play()if colour == Bet:Funds = Funds+(betsequence[counter]*2)counter = -1else:Funds = Funds-betsequence[counter]print(colour)totalcount = totalcountdef play():random.seed(a=None, version=2)rannum = random.uniform(0,1)result = rannum*14if (result > 1) and (result < 8):return "Red"elif result < 1:return "Green"else:return "Black"
Answer

You need to define the name before it is first used. In your case, moving the definition of play to before the while loop will solve the issue.

https://en.xdnf.cn/q/118593.html

Related Q&A

Error: unhashable type: dict

i have a problem with Django: I cant show the data from mysql database in the table. I see the error "Exception Value: unhashable type: dict" This is my code: views.py:List_of_date=El.objects…

terminal command line python3.3

Im following a book tutorial and its telling me to install python3.3 with the command linesudo apt-get install python3.3however Im getting errorsUnable to locate package python3.3 Couldnt find any pack…

SQLalchemy making errors after being updated to 1.4.0 [duplicate]

This question already has answers here:ImportError: cannot import name _ColumnEntity from sqlalchemy.orm.query(5 answers)ImportError: cannot import name _ColumnEntity Ubuntu20.10 [duplicate](1 answer)C…

Python string formatting with percentage (TypeError: not enough arguments for format string)

The following code fails to run.It goes through a CSV file and retrieves the values and formats them in a array of tuples (a insert query) to be used later. Problem is the csv last column is sometimes …

Circles touching edges

I am struggling with a program to tell whether a created disk touches the edge of a predefined box. The parser keeps saying things such asNameError: global name disksdescription is not defined Warning…

How to split data from a merged cell into other cells in its same row of a Python data frame?

I have a sample of a data frame which looks like this: +---+--------------------------------------------------------------------------------------+---------------+--------------------------------------…

Collect data in chunks from stdin: Python

I have the following Python code where I collect data from standard input into a list and run syntaxnet on it. The data is in the form of json objects from which I will extract the text field and feed …

Getting and calculating stuff through tkinter widets

I was wondering how to calculate stuff using tkinter buttons. Im making a simple program to calculate seconds to hours:minutes:seconds. The user inputs an integer using the entry widget on the seconds …

Why does this condition execute to false when it should execute to true?

I have this code in my spider basic.py file:if l.add_xpath(price, //*[@id="price"]/text(),MapCompose(lambda i: i.replace(,, ), float),re = [,.0-9]):l.add_value(available, 1) else:l.add_value(…

Convert nested JSON to CSV in Python 2.7

Have seen a lot of thread but unable to found the solution for mine. I want to convert one nested JSON to CSV in Python 2.7. The sample JSON file is as below:sample.json # My JSON file that mainly cont…