Thursday, 15 January 2015

python - Changing loop conditions to repurpose a number guessing game -


I am a new programmer with experience with Visual Basic for the application and recently changed to Python.

I am working on an estimate of the game and progress so far has been very good. The user records 4 points in the program. This program also creates a 4 digit number and shows whether any points are correct or not, this program gives YS or NS. Easy 1357 as a user estimate and 1358, shows YYYN as the output number in the form of output.

I am trying to work on the program again so that users show H or L that they need to estimate high or lower points if the guesses are wrong. If it is correct, So a y should be shown in normal form. I know that this is a condition in the loop that I need to change or I need to add another loop, but I'm struggling to see where to add it and how to write it. Does anyone have the solution?

Here is a part of my code for the program segment that gives results for the estimate.

  life = 10 while life & gt; 0: number = input ("Enter your guess:") for letter = '' I (in the range (numToGuess)): letter + = 'Y' if int (number [i]) == numToGuess [i] else 'N' if letter == 'Y' * lane (numToGuess): print ("good job!") Break print (letter) - = 1 other: print ("The game is over! You use all your efforts Done. ")  

Does anyone have the solution?

I like to use lists for this, I mean both right answers and The user estimates in different digits in two lists and then compare them.

Assume that the correct answer is '1234':

  remains = 10 correct_arice = 1234 correct_answer = [str (four) in str in four (correct_answer)] while Life & gt; 0: letter = '' number = input ("Enter your estimate:") number = [four] in str (number)] for four numbers if == correct_answer: print ("correct!") (Lane ( Right_ answer)): If true_ answer [i] == number [i]: letter + = 'y' alif correct_ answer [i] & gt; Number [i]: letter + = 'h' second: letter + = 'l' print ("your guess is wrong:", letter) life - = 1 print ("game over!")  

Now for example:

  Enter your estimate: 1111 Your guess is wrong: YHHH Enter your estimate: 1235 Your guess is wrong: YYYL Enter your estimate: 1234 correct is! Game Over! & Gt; & Gt; & Gt;  

No comments:

Post a Comment