Hey, I'm new to python so don't judge.

Callum Robinson cr2001 at hotmail.co.nz
Tue Jan 3 20:04:29 EST 2017


On Wednesday, January 4, 2017 at 1:45:22 PM UTC+13, Erik wrote:
> Hi Callum,
> 
> On 04/01/17 00:30, Callum Robinson wrote:
> > I feel like im missing something so blatantly obvious.
> 
> That's because you are ;). I don't want to come across as patronising, 
> but I want you to see it for yourself, so, here's a function definition 
> similar to yours that doesn't have the same syntax error that yours does:
> 
> def foo(spam, ham):
>      if spam == ham:
>          return "same"
>      return "different"
> 
> See the difference?
> 
> E.

I've figured out that out but I have a new issue. I like what you are doing making me figure this out as it helps me remember. I'll post the new code and the issue. If you could give me a hint that would be great. 

------------------------------------------
Issue
------------------------------------------

Traceback (most recent call last):
  File "D:/Python/random.py", line 6, in <module>
    computer_number = number.randint(1, 100)
NameError: name 'number' is not defined


-----------------------------------------
Here is the most recent code
-----------------------------------------


# mynumber.py
# this game uses a home made function
import random

#think of a number
computer_number = number.randint(1, 100)

#create the function is_same()
def is_same(target, number):
        if target == number:
            result="Win"
        elif target > number:
            result="Low"
        else:
            result="High"
        return result

# start the game
print("hello. \nI have thought of a number between 1 and 100.")

#collect the user's guess as an interger
guess = int(input("Can you guess it? "))
#Use our function
higher_or_lower = is_same(computer_number, guess)
#run the game untill the user is correct
while higher_or_lower != "win":
    if higher_or_lower == "low":
         guess = int(input("Sorry, you are too low. Try again."))
    else:
        guess = int(input("Sorry your are too high. Try again."))

    higher_or_lower = is_same(computer_number, guess)

#end of game
input("Correct!\nWell Done\n\n\nPress RETURN to exit.")
            
            
            




More information about the Python-list mailing list