0

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.

4
Contributors
5
Replies
26
Views
9 Months
Discussion Span
Last Post by Gribouillis
0

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.

0

@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

0

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

0

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.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.