I have been having a problem with a bit of code. I have readed Python documentation about local and global variables. As I understand it, local and global scope isn’t affected by if statements. My code is the follow: user = request.user if user == auction.user: owner = True print(owner) Nevertheless, i have this error: ..
Category : if-statement

I am trying to recreate the blue side of the table where the equation for dnvgl shape on excel is (=IF(‘LENGTH (m)’>(3*DEPTH d (m)),"Flat Long shaped","Box/round shaped"). I tried to do this on pandas using this formula. liftinput[‘DNVGL Shape’]= (‘Flat Long Shaped’ if liftinput[‘LENGTH (m)’] > (3*liftinput[‘DEPTH d (m)’]) else ‘Box/Round Shaped’) I got this ..
I am trying to count the number of occurrences of a specific letter(s) in a string. To give an example, I want to count the letter a and b in the string "acdjsfdklfdcfnqc" (String or the specific letters are not important). Firstly, I defined a container c that will count the occurrences of the letters ..
How can I write code so that in a game where a 3 digit number is randomly generated (first 2 digits can be 0) I check if the number contains a 9. However, the number cant be 963 or 369. The number is currently generated in a way where each digit is independently generated. Each ..
How can I write code so that in a game where a 3 digit number is randomly generated (first 2 digits can be 0) I check if the number contains a 9. However, the number cant be 963 or 369. The number is currently generated in a way where each digit is independently generated. Each ..
I’m having trouble figuring out where to place variables related to each coin and how to properly declare them. IE: Pennies = 1, Quarters = 25. I need to make minimum changes to the existing code, but need to figure out how to make it work. numPennies = int(input(‘Enter the number of pennies: ‘)) numNickels ..
So I was making my own terminal with a list of commands and a series of if-statements to check them. If the command does not exist, it returns an error. If the input is contained in the list of commands, regardless of which command, it will execute only the first if-statement. E.g. I enter 3 ..
I am having an issue with an if statement that I cannot figure out on my own. I am sure it’s simple, but it seems to be beyond my scope of Python knowledge. I am still very new. I am making a decision based text adventure mini game. Everything is working except for one if ..
BREAK DOWN OF PROJECT The user is asked to enter a number and a second number. a variable named results is created by adding the two numbers together. We search for the results in the 1st if statement in a dictionary named ans (short for answers). This part functions as it should. It than gives ..
Running into the age old problem of the infinite loop… Writing a text adventure game and have the game mechanics down; map and movement around it. Running into an issue with an infinite loop when I try to implement the other functionality – take items etc. Below are 2 snippets of the code including the ..
Recent Comments