Sign in to follow this  
balderin

Anyone help a python noob?

Recommended Posts

balderin    102
Hi! I'm a super noob just starting to learn python and programming in general. My problem is trying to verifiy a random number
but ending up with invalid syntax.

import random

heroAttack = random.randint (1, 10)
if heroAttack > 5
print (You hit!)
else:
print (You miss.)

I always get an invalid syntax at the number 5. Could somebody tell me what is wrong?

Share this post


Link to post
Share on other sites
Bacterius    13165
You need to end conditions by a colon (:). Also, I think you need "You hit!", "You miss." to be strings, but I could be wrong on this. Also you want to wrap Python code in code tags, because of indentation:


[CODE]import random
heroAttack = random.randint (1, 10)
if heroAttack > 5:
print ("You hit!")
else:
print ("You miss.")
[/CODE]

Share this post


Link to post
Share on other sites
6677    1054
2 things, thz is not a word.
Secondly if he's a noob letting him get used to variables is probably a nice idea. You are correct in that its shorter but who knows. HeroAttack could also be used for a damage calculation later on

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this