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

Callum Robinson cr2001 at hotmail.co.nz
Tue Jan 3 20:37:24 EST 2017


On Wednesday, January 4, 2017 at 12:49:28 PM UTC+13, Callum Robinson wrote:
> Im doing a new task from my teacher but i can't seem to find what is wrong with this code. Can anyone help?
> 
> #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 == "to 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.")

Hey again, i'm sorry for bothering you with so many questions i just did not want to keep asking my teacher who is on holiday these.

I have another issue where the code runs but i can guess every number from 1-100 but it always says Sorry your are too high. Try again. I don't understand what i have done to cause this.



More information about the Python-list mailing list