0

I'm new to python so this might be a stupid question but basically im trying to make a number guessing game and there are 2 problems, the first one is that if i try to bet 50 or more coins, it doesn't let me and the second one is that the if statement that checks if you were right or wrong, seems to be ignored.

import random
import time

coins = str(100)
print("you have " + coins + " coins")
num1 = str(random.randint(1, 20))
print(num1)
highlow = input(print("do you think the next number between 1 and 20 is higher(1) or lower(2)"))
bet = str(input(print("how much coins do you want to bet?")))
if bet == coins:
    print("you bet all your coins")
else:
    if bet > coins:
        print("you can't bet that many coins, you only have " + coins + " coins")
        time.sleep(3)
        quit()
    else:
        print("you bet " + bet + " coins")
time.sleep(3)
num2 = str(random.randint(1, 20))
print("the second number was " + num2)
time.sleep(1)
if num1 > num2:
    if highlow == 1:
        print("the second number was lower, you lost")
        coins = coins - bet
    elif highlow == 2:
        print("the second number was lower, you won")
        coins = coins + bet
elif num2 < num1:
    if highlow == 1:
        print("the second number was higher, you won")
        coins = coins + bet
    elif highlow == 2:
        print("the second number was lower, you lost")
        coins = coins - bet
time.sleep(1)
print("you have " + coins + " coins")

i tried to change the if statement around at the end so that it first checks if you guessed higher or lower but that doesn't work either.

Miro
  • 11
  • 1
    Side note: `str(input(print("text")))` is completely unnecessary. `input()` already prints its parameter, and returns a string. So just use `input("text")`. – B Remmelzwaal Mar 09 '23 at 11:14
  • 1
    `coins` and `bet` should be intergers (`int()`). In your case they are strings, thus comparison `"50" > "100"` doesn't do what you think it does. – Alexey S. Larionov Mar 09 '23 at 11:15
  • What you _do_ want to do is cast the inputs to integers using `int(input("text"))` so you can do comparisons. – B Remmelzwaal Mar 09 '23 at 11:15
  • For your second problem: [Python input never equals an integer](https://stackoverflow.com/questions/39775273) – Jorge Luis Mar 09 '23 at 11:15
  • For your first problem: [Why is my Python script printing "None" after using a function and using input(print())?](https://stackoverflow.com/questions/70462839) – Jorge Luis Mar 09 '23 at 11:19

0 Answers0