variable-assignment

How or when is a variable updated?

How or when is a variable updated? Question: I wrote this code (spoilers for LeetCode problem 13): roman_numbers = [(‘I’, 1), (‘V’, 5), (‘X’, 10), (‘L’, 50), (‘C’, 100), (‘D’, 500), (‘M’, 1000)] class Solution: def get_value(self, number): return dict(roman_numbers)[str(number)] def romanToInt(self, s: str) -> int: result = 0 letter_list = list(letter for letter in …

Total answers: 2

Dictionary Assignment Not Functioning As Intended

Dictionary Assignment Not Functioning As Intended Question: CONTEXT I’m creating a calculator. I’m at the point where I want my calculator to do BODMAS (start calculations with the inner most bracket). The user enters an expression, in this example it is: expression = (1+(1+1)) I have a function that splits up this function into ‘terms’ …

Total answers: 1

Local variable 'gamebot' referenced before assignment

Local variable 'gamebot' referenced before assignment Question: This is my question here:) My question is straight forward, the first program is the correct program but second program isnt, why ? gamebot = "OFF" def gamebot_status(): if gamebot == "OFF": gamebotTest = gamebot print("Gamebot is right now ", gamebotTest, "nTurning On gamebot in… n1 n2 n3 …

Total answers: 1

Problem with writing an objective oriented python assignment

Problem with writing an objective oriented python assignment Question: Can someone help me while writing an assignment? It is necessary to create a template for creating objects of the Student type. Each Student should have the following properties: It is necessary to create a template for creating objects of type Student. Every student should have …

Total answers: 1

Creating ID for every row based on the observations in variable

Creating ID for every row based on the observations in variable Question: A want to create a system where the observations in a variable refer to a number using Python. All the numbers from the (in this case) 5 different variables together form a unique code. The first number corresponds to the first variable. When …

Total answers: 1

Python ValueError: could not convert string to float: '1,000000E+06'

Python ValueError: could not convert string to float: '1,000000E+06' Question: I have a list of around 70 string values, all of them with the E+(05 or 06), which they should be converted to float (as whenever i try to print the values, it somehow ignores the 100000 or 1000000). raw_data = ‘EISTest16_10CV_01.txt’ # name of …

Total answers: 2

Consecutive letter removal of 3 or MORE consecutive letters

Consecutive letter removal of 3 or MORE consecutive letters Question: The program asks for a string and outputs the string remaining after removing groups of 3 or more meaning it can be 3, 4, 5, 6, and so on, consecutive identical characters. The removal of the groups continues until no more groups are found to …

Total answers: 1

Removal of 3 or more consecutive letters in a string given by the user

Removal of 3 or more consecutive letters in a string given by the user Question: The program asks for a string and outputs the string remaining after removing groups of 3 or more consecutive identical characters. The removal of the groups continues until no more groups are found to be removed. The program should allow …

Total answers: 1

Multiple changes to the same variable within different if statements

Multiple changes to the same variable within different if statements Question: SOLVED: I read through my code, it was a ‘bug’. When I copied the dice roll method from the ‘player character’, since it uses the same mechanics for the enemies, I set the damage to 0 if it rolls with one die on accident. …

Total answers: 1