What could be causing my code to only recognize the first condition and overlook the second one?

Can someone help me understand why my code is only evaluating the first condition and not checking for the second condition as well?

def identifyWeapon():
    if keyPress.positive:    
        if raySensor.hitObject['primaryWeapon']:
            own['primary'] = raySensor.hitObject['weaponName']
        elif raySensor.hitObject['secondaryWeapon']:
            own['secondary'] = raySensor.hitObject['weaponName']

identifyWeapon()            

Answer №1

It took me a whole day, but I finally figured it out! The issue was actually because I was using Boolean instead of a string in my code. It really made me think and I had to experiment with various solutions to get it right. Thank you all for your help!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to produce data on the server and then transmit it to the client?

Can you provide guidance on creating a webpage that prompts a python script to run on the server, and then displays the output of the script back in the browser? I'm put time into researching and seeking assistance during my web programming course. A ...

Performing G-testing in R and Python (Comparing Proportions between Two Samples)

While conducting the G test in both R and Python, I have come across different results. Surprisingly, the results from my Python code seem to be inaccurate, suggesting there might be a misapplication of the formula. The dataset is as follows: prfs Sex F ...

Ways to loop through xpath and verify image existence before executing specific actions

View Image Examining the image provided reveals two solutions: one for a flight and the other for a hotel. The objective is to iterate through each solution using XPATH. Success has been achieved in this aspect. The goal now is to verify the returned ima ...

The strategic placement of the modulo operation within a programming algorithm

I've been grappling with a certain problem that ultimately boils down to calculating the value of https://i.stack.imgur.com/ovS3p.png (n+m-2 Combinations m-1). Here's what I have so far. In situations where the result exceeds 10^9+7, I must out ...

Typical process of going through a list

Transitioning from Excel to Python, I am in need of help with finding the average for a list but for each new item. Consider the list below: x = [-3.2, 2.7, -8.5, -1.4] I initially attempted the following code: avg = sum(col)/len(col) This method resul ...

Guide to making Python's virtual machine output a stack trace

I'm currently faced with an issue on a server built using Python that freezes unexpectedly, causing the logging to also cease. I am curious if there is a command similar to Java's "kill -3" signal in Python that could print out the current stackt ...

Selenium in Python is having trouble locating an element using an absolute xpath that targets

After hours of research and browsing through numerous webpages and stackoverflow posts, I have managed to create a dynamic xPath for clicking on an element. However, despite my efforts, the click action is not working as intended... The main goal here is ...

Exploring the world of Python and Selenium with questions about chromedriver

I am planning to share my Python program with others and I would like to convert it into a .exe file using py2exe. However, I encountered an issue while using Selenium. chrome_path = r"C:\Users\Viktor\Desktop\chromedriver.exe" If user ...

What is the process for extracting the background using cv2.BackgroundSubtractorMOG2?

Is it possible to extract the background using cv2.BackgroundSubtractorMOG2 in Python? In simpler terms, is there a method to generate an image by analyzing the past n frames of a video that can serve as the background? ...

Expanding the dimensions of both 3D and 2D array

Currently, I am faced with a challenge involving a 3D array of shape (3, 4, 3) and a 2D array of shape (3, 3). My objective is to multiply these arrays in such a way that the ith element of the resulting 3D array corresponds to the product of the ith eleme ...

How can you traverse through CSS page numbers using Python?

Is there a way to create a loop that iterates through page numbers for aria-label? browser.find_element_by_css_selector('[aria-label="Page 1"').click() browser.find_element_by_css_selector('[aria-label="Page 2"').cli ...

Utilize an npm package or Python script to convert a .3ds file to either .obj, .collada, or .g

I have a collection of .3ds format files that I need to convert into gltf format. Are there any tools available to directly convert them into either .gltf format or collada/.obj format? I have already explored npm packages for converting collada/.obj to g ...

What is the best way to use SQL and Flask to automatically fill out a form based on a selection made from a

Looking for assistance with populating an HTML form by selecting a company from a dropdown menu. The desired result is similar to the example found here, using SQL and Flask. I'm unsure of how to retrieve the selected value from the <option> ta ...

Using 'cbc' in SolverFactory with Pyomo on Windows 10: A step-by-step guide

I've been experimenting with the 'cbc' solver in pyomo, implementing it like this: import pyomo.environ as pe solver = pe.SolverFactory('cbc') result = solver.solve(m) Currently, I've primarily used the built-in 'glpk& ...

Setting up pip or pipx and configuring the system path

I am using Debian stable on my machine and I am trying to install the binance connector library https://github.com/binance/binance-connector-python for querying binance. I have been using pipx and it seems like everything is going smoothly so far (detai ...

Python Webdriver Manager: Troubleshooting Linux Issue with Python Webdriver Manager

Trouble Using Webdriver Manager Python with Linux System Specifications: Distro - Manjaro Linux IDE: Visual Studio Code I recently followed a tutorial on using the Webdriver Manager in Python to streamline my workflow. However, I faced some issues when ...

What are some effective strategies for protecting against SQL injections in Flask-SQLAlchemy? Are there more efficient methods for importing data from CSV files?

I am currently working on a project that involves loading data from the internet into a table using Flask, SQLAlchemy with PostgreSQL/psycopg2. I find myself in a disagreement with one of my colleagues, whom I will refer to as "Dad." Dad insists that execu ...

Implementing an array of functions on an array of elements based on their positions

Imagine the scenario: def x_squared(x): result = x * x return result def twice_x(x): result = 2 * x return result def x_cubed(x): result = x * x * x return result x_values = np.array([1, 2, 3]) functions = np.array([x_squared, t ...

Tips for isolating the central object within an image using OpenCV

Struggling to isolate the center rectangle in the image using cv2.connectedComponentsWithStats. Unsure of how to achieve this. https://i.stack.imgur.com/ZXo3i.png This was my approach: gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, bw = cv2.threshold( ...

Unable to locate element by id in the search results on Amazon using Selenium

I have implemented the given python script: from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.firefox.options import Options from selenium.webdriver.support import ...