Feb-10-2019, 07:18 AM
G,day everyone
so i'm reasonably new to python coding, I've not done very much and am looking for some help. the code below is guessing number game my teacher got my class to do as a learning exercise. its not homework either. i'm just trying to learn more. so what I'm trying to achieve is when the players choice gets close to the computers choice. I want to say "Getting Warm", "Getting hot" or if the players choice is far from the computers choice "cold", "very cold". I don't know how to check if the player choice is close the computers choice and then let them know. I'm not looking for an answer exactly just something to put me on the right path, if i know if i know how to check if pc is in range of cc by 10 for example i cant then print getting hot or hotter. I appreciate your time, Thanks
so i'm reasonably new to python coding, I've not done very much and am looking for some help. the code below is guessing number game my teacher got my class to do as a learning exercise. its not homework either. i'm just trying to learn more. so what I'm trying to achieve is when the players choice gets close to the computers choice. I want to say "Getting Warm", "Getting hot" or if the players choice is far from the computers choice "cold", "very cold". I don't know how to check if the player choice is close the computers choice and then let them know. I'm not looking for an answer exactly just something to put me on the right path, if i know if i know how to check if pc is in range of cc by 10 for example i cant then print getting hot or hotter. I appreciate your time, Thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import random #variable names #cc = Computers Choice #pc = Players Choice cc = random.randint( 1 , 10 ) endgame = False attempts = 0 yes = True while (yes = = True ): while (endgame = = False ): pc = int ( input ( "choose a number between 1 -10 " )) attempts = attempts + 1 #determines if the player choice is the right choice then ends the game if (pc = = cc): print ( "well done you guessed correctly" ) print ( "Total Attempts Made " + str (attempts)) endgame = True #determining if the player choice is higher or lower and letting them know what to further guess for elif (pc<cc): print ( "Higher" ) else : print ( "lower" ) #Based on the amount attempts made determines wherether the game ends if (attempts = = 5 ): endgame = True print ( "You loose" ) #Winning a reward based on the attempts made by the player if attempts = = 1 and endgame = = True : print ( "You Have Won a Car!!!" ) elif attempts = = 2 and endgame = = True : print ( "You Have Won a Boat!!!" ) elif attempts = = 3 and endgame = = True : print ( "You Have Won a Holidy!!!" ) #how the player chooses if they wish to play again or not restart = input ( "Do you wan't to play again, print 'yes'-'y' or 'no'-'n' " ) if restart = = "yes" or restart = = "y" : yes = True endgame = False attempts = 0 cc = random.randint( 1 , 10 ) if restart = = "no" or restart = = "n" : yes = False print ( "Thanks for playing" ) |