Posts

Showing posts from March, 2022

Scissor, Paper , Rock Game

Image
Scissor, Paper , Rock Game code # Scissors Paper Rock GAME import random def gameWin(comp,you): if comp == you: return None elif comp == 's': if you == 'p': return False elif you == 'r': return True elif comp == 'p': if you == 'r': return False elif you == 's': return True elif comp == 'r': if you == 's': return False elif you == 'p': return True print("comp turn: Scissors(s) Paper(p) or Rock(r)?") randNo = random.randint(1,3) if randNo == 1: comp = 's' elif randNo == 2: comp = 'p' elif randNo == 3: comp = 'r' you = input("Your turn: Scissors(s) Paper(p) or Rock(r)?") a = gameWin(comp,you) print(f"Computer chose {comp}") print(f"You chose {you}") if a == None: print ("...

Guess the right number

Guess the right number from 0 to 100 import random randNumber = random.randint(1,100) # print(randNumber) userGuess = None guesses = 0 while (userGuess != randNumber): userGuess = int(input("Enter your guess\n")) guesses += 1 if (userGuess == randNumber) : print("You guessd it right!") else: if (userGuess>randNumber): print("You guessd it worng! Enter a smaller number") else: print("You guessd it worng! Enter a larger number") print(f"You gussed the right number in {guesses} guesses") code for save and update highscore with open("high_score.txt","r") as f: highscore = int(f.read()) if(guesses > highscore): print('You just break high score!') with open("high_score.txt",'w') as f: f.write(str(guesses))