So I just started coding and this is probably a stupid mistake but i wrote this code:

print("would you like to roll the dice?")
input('enter answer')
yes="yes"
no="no"
if "yes":
    from random import randint
    print(randint(0,6))
elif "no":
    print("error")

so my problem is that when i type no i want the output to be error, but instead it still spits out a number, and i have no idea how to fix it.

Agree with rproffitt. There are some excellent tutorials out there which teach the basics carefully and efficiently - at this stage invest effort in figuring out from those what your errors are, you'll learn more deeply that way anyway. I quite like an app called Sololearn for that sort of thing.

@rproffitt I just started learning yesterday, but i had downloaded this app about 4 months ago i believe it was off of reddit and someone reccomended it to me

Just in case anyone is also wondering what the app is called it's PyCharm Edu

The home site www.python.org has a special page for beginners with good links, you could perhaps start from here.

Concerning your specific code, without entering into details

  • At line 2, input() returns a value: the user's answer. You're ignoring this value.
  • At line 5, if expression is always true when expression is a non empty character string. Instead of testing the constant string "yes", your code should be testing whether the user's answer was yes.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.