I am making a word quiz game in visual studio 2022. I have found a way to check if a word is a real word using WordNet database files. My question is how to select a random word from WordNet in order to make user guess it.Method like wordNet.GetAllSynsets(); does not exists. Only wordNet.AllWords; i have found that is more similar to what i want. But i dont know how to work with it.
mercredi 3 mai 2023
How to select a random word from WordNet Library C#
How to make the r become 1 and stay like that [closed]
Whenever I repeat the loop, the r reverts back to 0. I want to keep it at 1 unless something else brings it back to 0.
r = 0 rand = random.randint(1,3) if rand == 2: r = 1 print("r:" + str(r))
mardi 2 mai 2023
Python: random number game with play again where loop fail
This is my first code ever in Python and I'm sure many think "Ohh.. should have done this or that!". I'm aware and I'm here to learn.
I believe a lot of my errors/problems are related to indentation. But there's plenty of it. I also suspect that I'm mixing things up while in loop or if/elif's. I pasted the terminal output into notepad for reference. I'll post my code below all.
It started really simple but then I wanted to make more and when you make more and don't know what you're doing you tend to google stuff. And when googling stuff make you use different peoples thoughts and that seems to clash sometimes. So if it looks like it's a code written by multiple personalities you're not far from the truth.
What I want is:
- Correct action on yes/no alternatives.
- Warning and forced reentry when input isn't integers and/or yes/no where it's supposed to be.
- When new game starts the random_number must reset. This doesn't work when it starts from "Game ended after 10 trials!". It keeps the tries from last round.
My problem(s) is:
1. While reaching the end of a game the game ask you if you want to play again if you guessed the right #. I'm not sure what I changed but it worked earlier, so my guess is that it has something to do with indentation.
2. New run: Input is "no" and should exit but it start a new round. And the new round start at the "guess"-line (#45) and not at game() (#33). This action doesn't reset the random#.
# Gissa slumptal mellan 1 - 100 i Python
"""
The user must guess a number between 1-100, that the program
give by using the built-in function randint.
The user gets 10 attempts before the game ends. The user gets
an indication of how close the guess is to the correct number and another if
this one is in the range of +-3 <> random_number.
The program tells you how many times you guessed and what the number was.
"""
# Use module random and set guessed to 0.
# could have used from random import randint
import random
guessed = 0
# Declare variable and generate random number in range 1 - 100.
def get_random_number():
random_number = random.randrange(1,100)
return random_number
def startGame():
answer = input("Do you want to play a game? Answer yes or no.\n")
if answer == "yes":
while guessed != True:
game()
if answer == "no":
print("See you later!")
# Ask user to guess the number in less than 11 times(10 tries).
# The answer will be in variable "guess".
def game():
print("\nI guessed a number between 1-100")
print("Can you guess which in less than 10 guesses?")
# Variable to how many tries and boolean on found.
tries = 0
found = False
random_number = get_random_number()
while not found:
while True:
try:
guess = int(input("Guess which number I'm thinking of!\n"))
break
except ValueError:
print("Only integers please!")
continue
if guess == random_number:
print(str(random_number) + "! It was right! You did " + str(tries) + " attempts. Good work!\n")
found = True
# Ask if user would like to try again.
while True:
a = str(input("Do you want to try one more time?.\n"))
if a in ("yes", "no"):
print("Just answer yes or no, please.\n")
continue
if a=="yes":
game()
if a=="no": # If I answer "no", I go to startGame again, but "yes" works
print("Welcome back!")
#break
# The program check if user was right and give response.
# When in range of +-3 from randomnumber give a notice.
elif (abs(guess - random_number) <= 3):
print("It's really close now!")
stillGuessing = True
elif guess < random_number:
print("Sorry, it was too low. Try again!\n")
stillGuessing = True
elif guess > random_number:
print("Sorry, it was too high. Try again!\n")
stillGuessing = True
# Loopcount.
tries += 1
# End game after 10 tries and ask user if they want to restart.
if tries == 10:
print("\nThe correct answer was: " + str(random_number) + ".")
print("Game ended after 10 tries! Do you want to play again?")
# Ask for Y/N. If not Y/N = errormessage and try again.
while True:
b = str(input("Answer yes or no to try again.\n"))
if b in ("ues", "no"):
break
print("Just answer yes or no, please.\n")
# if "yes" I return to guess without new random_number
if b=="yes":
game()
# if "no" I return to game() - I want the run to end with print("Welcome back!")
if b== "no":
print("Welcome back!")
break
def main():
startGame()
if __name__ == "__main__":
main()
# Hold until input.
#print()
I've tried to change indentation, tried different valueError/string controls and rearrange the code when I understood that I've written code in the wrong place and so on.. As the code got bigger I had to start using functions etc. I started with a simple thing that outgrow me. Fast.
I expected something like this:
-
Ask player to play
-
If yes - start game, if no - end run.
- check if input is "yes" or "no"
- If not, prompt reenter yes/no
-
Output to user about game and prompt action.
-
Game start: 10 tries to get random#
- check if input is int
- If not, ask for reentry a int
- If guess is correct: Tell "Congrats, #tries and ask for a new game".
- check if input is "yes" or "no"
- If not, ask for only "yes" or "no"
- If not, reenter yes/no
- If yes: start new game (with random# reset)
- If no: print "Welcome back" - end run.
-
If not right in 10 guesses: Tell user the random#, message about 10 tries and ask for a new game.
- If yes: reset random#, go to game() and start over
- If no: print "Welcome back" - end run.
How to Identify and compare all the random variables of a mixed polynomial model of degree n through AIC or AICc?
Please, is there an algorithm or a package to identify and compare the random variables of a mixed polynomial model of degree n through AIC or AICc in R?
Example: Third degree
lmer(y ~x + x2 + x3 + (1|id), data, REML=T)
lmer(y ~x + x2 + x3 + (1|id) + (0+x|id), data, REML=T)
lmer(y ~x + x2 + x3 + (1+x|id), data, REML=T)
lmer(y ~x + x2 + x3 + (1|id) + (0+x|id) + (0+x2|id), data, REML=T)
lmer(y ~x + x2 + x3 + (1+x+x2+x3|id), data, REML=T)
I have tried the dredge function from the MuMIn package but it compares instead fixed effects like:
lmer(y ~x + (1|id), data, REML=F)
lmer(y ~x + x2 + (1|id), data, REML=F)
lmer(y ~x + x2 + x3 + (1|id), data, REML=F)
Thank you so much
lundi 1 mai 2023
python set random seed, but results not reusing
I'm training a simple neural network model in python, I need to run batch experiments to test the performance of different module configurations by executing python train.py.
- train configs:
- dataset_A, dataset_B, dataset_C, total 3 datasets
- total 19 model configurations.
- Python training mode:
-
if I using 2 for loops to generate some results, some of them are wrong. If I rerun the wrong results seperately, the correct results will be produced, even if run multiple times.
-
I split the 3 datasets, modify the
train.pyand run it one dataset at a time, I get different results than in training mode 1).
I set the random seed in the ./utils/util.py:
def set_seed(seed):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
In train.py, it call the function set_seed(42). In short, if I set exact same configuration, mutilple runs will produce the same results. However, if I just change the order of the datasets list, I will have different results. I would be grateful if someone could give me some advice.
Need multiple values from for loop
I want to repeat the for loop which get us new values every time. Whenever I will run the for loop I should get the values different. Please solve my problem
let hex = 'ABCDEF0123456789';
let res = '';
for (let i = 1; i <= 6; i++) {
res += hex.charAt(Math.floor(Math.random() * hex.length));
// console.log(i);
}
I want to get new values every time when I call or run the for loop. For Example - If I print the value of res multiple times. Every time I want the value different
i need help getting seed = os.clock to output a integer
I am trying to get a random number generation but keep getting this syntax.
lua5.3: Main.lua:3: bad argument #1 to 'random' (number has no integer representation)
stack traceback:
[C]: in function 'math.random'
Main.lua:3: in main chunk
[C]: in ?
I tried to use this to get a random number but it doesn`t have a integer representation.
seed = os.clock()
print(seed)
e = math.random(seed)
print(e)