Tips for converting the 'numericals' in the input provided by the user into the initial point of a loop

I am in the process of developing a program to analyze the game Baccarat, and while I have a good grasp of the basics, I require assistance in enabling users to paste multiple games at once. Below is an example:

games = input('Enter the games you wish to test: ')

players input(1,B,T,P,B,B,B,P,P,P,T,P,P,P,P,T,B,P,P,B,P,P,B,B,P,P,B,P,B,P,T,B,T,B,P,P,T,B,P,P,B,P,P,T,P,P,P,P,P,B,P,B,B,P,B,B,P,B,B,P,B,B,B,B,P,B,P,B,P,T,P,B,B,B,P,B,B,P,P,P
2,T,P,B,P,B,B,P,P,B,B,T,P,B,B,T,P,P,B,B,B,B,P,T,B,T,B,B,B,P,P,B,P,P,P,B,P,B,P,T,B,P,B,P,B,B,B,B,P,B,B,B,P,P,P,B,T,B,P,B,B,P,B,B,P,B,P,P,B,B,P,P,P,B,B,P,B,P,P,P,P,T
3,P,P,B,B,P,B,T,T,B,P,P,B,B,B,P,B,B,P,P,B,P,T,P,B,P,P,P,P,B,B,B,B,B,T,P,P,P,P,P,P,P,B,P,B,B,P,B,B,P,T,B,P,P,P,B,B,B,P,P,B,P,P,B,B,P,P,P,B,P,B,P,B,B,B,B,B,B,P,P,T,B,P,B,P,P)

Although I have a basic understanding of Python programming and managed to create a program for manual input and result verification, I am struggling with implementing a loop to accommodate pasting and copying 100 games at once. Specifically, I need guidance on how to iterate through each number in the game series.

Here's a snippet of the code arrangement I believe would work:

bank = 1000
for number in games:
     number = games[0]
     if games[2] == 'B':
        bank += 7.60
     elif games[4] == 'B':
        bank += 6.25

Essentially, I aim for the program to initiate at games[0], move to the first occurrence of 'B' at games[2], halt there, then repeat the cycle with the next number, e.g., '2', and subsequent iterations.

I appreciate any insights or solutions offered by contributors.

Answer №1

To iterate through the elements of an object, you can utilize a for loop. By eliminating the line number = games[0], and modifying the lines bank += and bank -=, you can achieve the desired functionality:

bank = 100
for n in games:
    if n == 'B':
        bank += 7  # This could be replaced with any code or function.
    elif n == 'P':
        bank -= 7  # Similarly, this condition could execute custom logic.
    elif n == 'T':
        bank += 1

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

Selenium failing to interact with element

Seeking help with clicking a checkbox element: <input checked="checked" class="iceSelBoolChkbx" id="mainContentId:newSerchCheckBox" name="mainContentId:newSerchCheckBox" onblur="setFocus('');" onclick="var form=formOf(this);iceSubmitPartia ...

Is it incorrect to run the script multiple times in order for it to function properly?

After attempting to execute this script using both a while loop and a for loop, I noticed that it stops working after just one repetition. driver.find_element_by_class_name("submit").click() x = driver.find_element_by_class_name("submit" ...

Tips for seamlessly incorporating MongoMock with Pymongo-Flask

Looking to create unit tests for our mongo code using mongomock as the backend. However, facing a challenge with Flask-PyMongo which has a convenience class (find_one_or_404) added on top of the Collection class, complicating straight MongoMock substitut ...

Changing Unicode characters into Python

Similar Question: Convert Unicode to UTF-8 Python I am currently delving into the world of Python programming, tackling my very first script. This script takes text from a plist string, performs various operations on it, and then compiles it into an H ...

Creating a hover effect for a mouse in PyQt5 simulation

Is there a way to simulate mouse hover for PyQt5 to a specific coordinate, possibly using QPoint? import sys from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import Qt, QUrl, QTimer from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEngine ...

Translating data between Python and MATLAB by decoding binary files

I am encountering a significant issue with the struct.unpack function in Python. I have a binary file that follows a specific format, which can be written either in MATLAB or Python. When I write data to a binary file in Python and read it back, everythin ...

Having trouble installing the Binance API in PyCharm

Having some trouble installing the python-binance api on PyCharm. When I try running python -m pip install python-binance in the terminal, I encounter an error message that says: Python was not found; run without arguments to install from the Microsoft St ...

How does utilizing app.on_event("startup") differ from simply including additional lines in the main.py file within a fastapi application?

I'm feeling a bit puzzled about the purpose of using a @app.on_event("startup") statement. (doc: ) Is there a benefit to encapsulating the code within a @app.on_even("startup") block instead of just placing it at the beginning of ...

Using Selenium to extract data from a table in Python

I am currently exploring web scraping techniques using Python's Selenium library. My goal is to extract data from a table on a website using Selenium. Since I am still learning Python and Selenium, please bear with me if my code seems amateurish. f ...

Combining vertical cells with openpyxl

I'm currently working on a Python script to standardize Excel files using openpyxl. The code is almost finished, but I'm facing some challenges when attempting to achieve two specific tasks: For columns A & B starting from row #7, I need to me ...

Please indicate the number of cores in the `n_jobs` parameter

Within Sklearn, the n_jobs parameter is utilized in various functions to specify the number of cores to be used. This allows users to dictate the amount of processing power allocated for a specific task; for instance, inputting 1 uses one core while -1 s ...

Exploring the intricacies of gathering network data using Selenium

When capturing network traffic on Selenium objects for HTTP post requests, the JSON string returned includes request headers but not the body parameters of the post message. Here's the code in question: host = "localhost" port = "4444" browser = r"* ...

Adding rows together using conditions in the Pandas library

I'm trying to figure out how to sum a subset of rows based on two indices in Pandas. The first index groups the rows, while the second index determines which rows to sum. To illustrate this, let's consider the following dataframe: index1 | index ...

automate text selection in a browser using Selenium with Python

I'm trying to retrieve all values from a textbox using Selenium in Python. Here's the code I have so far: # -*- coding: UTF-8 -* from selenium import webdriver #open webdriver for specific browser import requests import time def getListZip(z ...

What is the best way to utilize the fixture function's return value and data as parameters in a pytest test case?

When I receive parameters from command lines, my goal is to utilize these parameters as variables in test cases. Specifically, I am interested in employing parametrized tests within the same test case. Is it appropriate to execute it as shown below? conft ...

Guide to utilizing fancyimpute within PyCharm

After successfully installing fancyimpute on Anaconda using the command pip install fancyimpute, I encountered an issue while trying to access it in PyCharm where Anaconda is set as the interpreter. Despite searching meticulously in the Settings/Project ...

Navigating through XML nodes in Python relative to a starting point

I am shocked that I can achieve the following using VBA but not Python. My goal is to transform returned XML data from an API into a usable format. Looking at the sample structure provided below, it requires nested looping. The issue lies in the fact tha ...

Finding specific text within an HTML tag using Selenium can be achieved by implementing certain techniques

Can someone help me extract the price of 234,40 € from the HTML code below using selenium? <a class="js-sku-link sku-link" title="Samsung Galaxy Watch4 Classic Bluetooth Stainless Steel 46mm Αδιάβροχο με Παλμογράφο (Black)" dat ...

Python: The best method to divide a sentence into approximately equal sections

I've been attempting to develop a function that can divide a sentence into n lines, aiming for as even of distribution as possible. However, I'm encountering issues where either the first or last line ends up significantly longer than the rest. ...

`Can Beautiful Soup extract data (text) from elements that share the same class identifier?`

Currently working on a personal project focused on web scraping, using beautiful soup to extract data from a website. Encountered an issue where data with the same class but different attributes is present. For instance: <div class="pi--secondary-price ...