-2
saldo = str("1000")#how much money you have
bet = input("kuinka paljon rahaa laitat peliin: ")#how much do you want to bet

while True:
    if bet == str():
        print("täytyy olla numero")#needs to be a number
    else:
        break

I expect it to break.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
  • And what do you reckon `if bet == str()` does? – B Remmelzwaal Jun 17 '23 at 11:28
  • Shuld be `if bet == saldo:` – toyota Supra Jun 17 '23 at 11:34
  • `input` will always return a `str` instance unless you convert it to something else. To check if something is a `str` use `isinstance(bet, str)` but in this case that is always true since you never use the `int` or `float` functions – mousetail Jun 17 '23 at 11:38
  • Does this answer your question? [How can I check if string input is a number?](https://stackoverflow.com/questions/5424716/how-can-i-check-if-string-input-is-a-number) – mkrieger1 Jun 17 '23 at 11:38

1 Answers1

1
class str(object)
    ...
    Create a new string object from the given object.

Meaning

if bet == str():

Will check bet against the result of str() which is an empty string. Also, using input will always give you a string, so there is no need to check whether it is a string. If you enter 1 for instance, you will get the string "1". If you want to verify the user input was indeed a number, you'll need other checks, for instance:

import string
foo = input('foo: ')
if not foo in string.digits:
   ...

or

foo = input('foo: ')
try:
    bar = int(foo)
except ValueError:
    print("This wasn't a number.")

You'll likely want to put your input in your loop as well, if I understand your intentions correctly. For instance:

saldo = 1000
while True:
    bet = input('bet: ')
    try:
        foo = int(bet)
        break
    except:
        print("This wasn't a number, try again.")
        
    
srn
  • 614
  • 3
  • 15