Python Forum
Making a percentile dice roller and dice roller - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Making a percentile dice roller and dice roller (/thread-13142.html)



Making a percentile dice roller and dice roller - Fixer243 - Sep-30-2018

So I believe i have the general concept of of what i am doing for this but I may not. I havn't programmed in a long 3 years. So I am pretty rusty!

Before you look at the code my idea is to have the percentile dice there so I created the bounderies of the amount that it can go with the min and the max. After I created the roll for the print so when the roll is less well you will get it from there. What i'm more or less confused on is I how to get the host to have person who starts the command, and the user being the one who bet as well as the amount the user is betting. Hell I could be way off and have no idea too.
What i currently have is pretty basic.


import random
min = 1
max = 100

B55x2 = '!55x2 {User} {Ammount}'
	while B55x2 == '!55x2 {User} {Ammount}'
		print( {User} ' bet on 55x2 vs ' {Host} ' for a bet of ' {Amount}


roll = random.randint(min, max)
	if roll > 54:
		print ( {Host} ' rolled ' {roll} ' with percentile dice')
		print ( {User} ' has Won their bet!')
	if roll < 55:
		print( {Host} ' rolled ' {roll} ' with percentile dice')
		print( {Host} ' has Lost their bet!')



RE: Making a percentile dice roller and dice roller - ichabod801 - Sep-30-2018

You are missing a close parentheses at the end of line 7. You appear to be using f-string syntax, but inconsistently and incorrectly. '!55x2 {User} {Ammount}' is the most correct you have, but you need an 'f' before the string (and User and Ammount need to be defined).

I don't know why your while loop is indented, and it will never end (you never change B55x2 within the loop). I don't know why your if statements are indented.


RE: Making a percentile dice roller and dice roller - gruntfutuk - Sep-30-2018

I'm not clear where you are going with this, especially the B55x2 line, so I've take the liberty of rewriting and extending what you've shared somewhat in the hope it will give you some ideas on how to achieve your intended objective.

In your original code, there is no means of entering/varying the amount, so I've chosen to make this a random amount, and I've also given the user an opening balance that the amount comes off of. If they win, they get their stake back, otherwise they lose their stake. (Incidentally, you'd varied the spelling of the amount variable.)

When the user runs out of money or either the host or the user gets a certain number of wins, the game ends. Your current code has an infinite loop in it.

I've shown how to use f-strings properly. (There could be calculations or functions calls inside of the {} if you wanted.)

The convention in Python followed by the majority of programmers is to use all lowercase in variable names, so I changed your variable names accordingly.

from random import randint
min = 1
max = 100

user = 'User'
host = 'Host'
amount = 10
user_balance = 1000

max_wins = 100
user_wins = 0  # introduced so the while loop does not run forever
host_wins = 0
 
B55x2 = f'!55x2 {User} {Amount}'  # no idea what this is for as it is never changed
while user_wins < max_wins and host_wins < max_wins and user_balance > 0:
    amount = randint(1, user_balance)
    print(f'{user} bet on 55x2 vs {host} for a bet of {amount}')
    roll = randint(min, max)
    print (f'{host} rolled {roll} with percentile dice')
    if roll > 54:
        print(f'{user} has Won their bet!')
        user_wins += 1
        user_balance += amount
    else:
        print(f'{host} has Lost their bet!')
        host_wins += 1
        user_balance -= amount
        
print(f'Host wins: {host_wins}, User wins: {user_wins} and balance: {user_balance}')