Hey, i appreciate anybody who use up some of their own time to help me. I'n a newbie to python and i have a couple problems.

First, the score NEVER gets updated.

Second, i'm unable to select the same menu option twice in a row (eg select 'letterguess' first, complete it then unable to select it again), so i'd have to go back an forth between option 1 and option 2.

Thanks for any help

# opens the current highscore from a text file
def highscore():
try:
highscore = open("topscore.txt","r")
print topscore
highscore.close
except:
print "error"
topscore = 0

# randomly chooses a word from a list
def getWord(wordList,Hintlist):
randompick = random.randrange(0,len(wordList)-1)
wordChoice = random.choice(wordList)
print "The length of the word is ", len(wordChoice)
print Hintlist[randompick]
return wordChoice

# allows the user to guess the letters in a word
def letterguess(wordList,Hintlist,score):
score == letterguess
wordChoice = getWord(wordList,Hintlist)
print "You have 6 letter guesses"
global guessnum
while guessnum!=6:
letter = raw_input("Please choose a letter")
guessnum = guessnum + 1
if letter in wordChoice:
print "The letter you guessed is in the word"
else:
print "Sorry, the letter you guessed is not in the word"
wordGuess(wordChoice,score)
return score

# this function allows the user 3 guesses to guess the whole word
def wordGuess(wordChoice,score):
score == wordGuess
while wholeguess!=3:
global wholeguess
userguess = raw_input("Try to guess the full word")
if userguess == wordChoice:
print 'Congratulations, you guessed the correct word'
score = score + 1
return score
else:
print "Sorry, you didn't guess the correct word"
wholeguess = wholeguess + 1
return score

# jumbles up a word
def wordJumble(wordList,Hintlist,score):
score == wordJumble
wordChoice = getWord(wordList,Hintlist)
high = len(wordChoice)
low = -len(wordChoice)
for i in range(10):
position = random.randrange(low,high)
print "word[", position, "]\t", wordChoice[position]
wordGuess(wordChoice,score)
return score

# checks the users score
def checkscore(player,score):
print player, "you have scored", score, "points"

# replaces the topscore with the new topscore
def replacement(topscore,thisplayer):
if thisplayer > topscore:
print "You are now the top scorer"
text_file = open("topscore.txt","w")
text_file.close()
else:
print "You have not topped the score this time"

# this is the options menu
1. Guess the word
2. Word Jumble
4. Exit """

import random

thisplayer = 0
wholeguess = 0
guessnum = 0
score = 0

wordList = ['albatross','donkey','spaghetti','geranium','binary']
Hintlist = ['seabird','slow animal','italian meal','element','0100110']

topscore = highscore()

print "Hi", player
thisplayer = score
replacement(topscore,thisplayer)
break
print "error message"
3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by vegaseat

score == wordJumble

This does nothing

You should use if ... elif ... else for if statement at last lines. Most stuff you are doing by yourself could be done by standard functions, like random.choice and random.sample.

score parameter given to functions is 0, so score is allways zero.

score = 0
snipeti snip
thisplayer = score

Edited by pyTony

Oops, forgot to get rid of those. They weren't supposed to be there.

Your global statements do not also make any kind of sense as those variables are only used locally and you are not using returned values from the functions for games.

You need to actually write the new high score out to file ...

def replacement(topscore,thisplayer):
if thisplayer > topscore:
print "You are now the top scorer"
text_file = open("topscore.txt","w")
text_file.write(str(thisplayer))
text_file.close()
else:
print "You have not topped the score this time"

# testing ...
topscore = 100
thisplayer = 155
replacement(topscore,thisplayer)

You can include the checking of the correct answer in the menu() function this way ...

while True:
1. Guess the word
2. Word Jumble