0
import time
import random
print("Welcome to double up!")
pscore = 1
pscore = str(pscore)
print("Your current balance is "+pscore+", would you like to double or 
quit?")
while pscore != 0:
    pscore = str(pscore)
    print("Your current balance is "+pscore+"!")
    pscore = int(pscore)
    choice = input("d/q :")
    if choice == ("d")or("D"): #later simplify cases
        luck = random.randint(1,100)
        if luck > 75:
            print("Upgrade failed!")
            pscore = 0
        else:
            print("Upgrade complete!")
            pscore = pscore * 2
    else: #ERROR
        print("Incorrect command! Please retry!")

The code line tagged with #ERROR doesn't run, no matter what I input as the variable 'choice' any help?

I would also welcome anything I can do to help cleanup my code, very new :p

https://pastebin.com/dPbpZfcy - The code as I messed up formatting on this site

Lit
  • 15
  • 4
  • 1
    It definitely shouldn't run. You have indentation errors. – cs95 Jul 21 '17 at 18:18
  • @cᴏʟᴅsᴘᴇᴇᴅ Well could you tell me where? – Lit Jul 21 '17 at 18:19
  • 2
    `if choice == ("d")or("D"): #later simplify cases` unindent this one level – jacoblaw Jul 21 '17 at 18:21
  • @AyyLmao https://pastebin.com/j3PxKXLE – cs95 Jul 21 '17 at 18:21
  • Don't convert pscore back and forth between an integer and string, just use str(pscore) when you need the string representation, no need to redefine the variable – yinnonsanders Jul 21 '17 at 18:21
  • I can't even get this to allow me to input something for the `choice` prompt. If I run the code exactly as-is, I get a SyntaxError on line 6. If I move `quit?")` so it's on the same line as the rest of the print statement, I get `IndentationError: unexpected indent` on line 12. If your code is executing up until the point where it asks you "d/q :", then it's not the same as the code you're showing us. – Kevin Jul 21 '17 at 18:22
  • 1
    Once the indentation problem is fixed, this is probably a duplicate of [Why does `a == b or c or d` always evaluate to True?](https://stackoverflow.com/q/20002503/953482) – Kevin Jul 21 '17 at 18:24
  • Possible duplicate of [Why does \`a == b or c or d\` always evaluate to True?](https://stackoverflow.com/questions/20002503/why-does-a-b-or-c-or-d-always-evaluate-to-true) – Foon Jul 21 '17 at 18:39

5 Answers5

1

Unindent the if choice ... line by one level. Then, change the if statement to say this:

if choice in ('d', 'D'):

What you had previously will always evaluate to true and the else will never be executed.

Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
0

Your if choice == ("d")or("D"): #later simplify cases line have the wrong identation.

Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
  • The indentation is a problem, but it isn't the only problem. And the indentation problem probably isn't even present in the OP's original code, or else it would flat-out fail to run entirely, rather than execute but never execute the `else`. – Kevin Jul 21 '17 at 18:23
0

Unindent this line:

if choice == ("d")or("D"): #later simplify cases
whackamadoodle3000
  • 6,684
  • 4
  • 27
  • 44
  • don't know why you were downvoted, thats correct. – jacoblaw Jul 21 '17 at 18:22
  • The indentation is a problem, but it isn't the only problem. And the indentation problem probably isn't even present in the OP's original code, or else it would flat-out fail to run entirely, rather than execute but never execute the `else`. – Kevin Jul 21 '17 at 18:23
0

Two problems: one is that the line

if choice == ("d")or("D"): #later simplify cases

must be unindented. The second problem is that the if statement returns true if choice == ("d") or if ("D"), the second of which is always true.

yinnonsanders
  • 1,831
  • 11
  • 28
0
# import time - Unused. you can remove this line
import random
print("Welcome to double up!")
pscore = 1
pscore = str(pscore)
print("Your current balance is "+pscore+", would you like to double or quit?")
while pscore != 0:
    pscore = str(pscore)
    print("Your current balance is "+pscore+"!")
    pscore = int(pscore)
    choice = input("d/q :")
    if choice == ("d")or("D"): #later simplify cases   # <<< Indent here.
        luck = random.randint(1,100)
        if luck > 75:
            print("Upgrade failed!")
            pscore = 0
        else:
            print("Upgrade complete!")
            pscore = pscore * 2
    else: #ERROR
        print("Incorrect command! Please retry!")
yantaq
  • 3,968
  • 2
  • 33
  • 34