-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from lakshyabhasin509/lakshyaBhasin
Added a few CLI game - LAKSHYA BHASIN
- Loading branch information
Showing
5 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
logo=""" | ||
.------. _ _ _ _ _ | ||
|A_ _ |. | | | | | | (_) | | | ||
|( \/ ).-----. | |__ | | __ _ ___| | ___ __ _ ___| | __ | ||
| \ /|K /\ | | '_ \| |/ _` |/ __| |/ / |/ _` |/ __| |/ / | ||
| \/ | / \ | | |_) | | (_| | (__| <| | (_| | (__| < | ||
`-----| \ / | |_.__/|_|\__,_|\___|_|\_\ |\__,_|\___|_|\_\\ | ||
| \/ K| _/ | | ||
`------' |__/ | ||
""" | ||
import random | ||
|
||
print(logo) | ||
cards=[11,2,3,4,5,6,7,8,9,10,10,10,10] | ||
|
||
player=[] | ||
computer=[] | ||
|
||
player_sum=0 | ||
computer_sum=0 | ||
|
||
player.append(random.choice(cards)) | ||
|
||
|
||
rand = random.choice(cards) | ||
if (rand == 11 and rand + computer_sum > 21): | ||
player.append(1) | ||
else: | ||
player.append(rand) | ||
|
||
|
||
computer.append(random.choice(cards)) | ||
|
||
|
||
randco = random.choice(cards) | ||
if (rand == 11 and rand + computer_sum > 21): | ||
computer.append(1) | ||
else: | ||
computer.append(rand) | ||
|
||
player_sum+=player[0]+player[1] | ||
computer_sum+=computer[0]+computer[1] | ||
|
||
while(player_sum<=21): | ||
print(f"Your cards : {player} ,current score : {player_sum}") | ||
print(f"Computer's first card : {computer[0]}") | ||
|
||
accept=input("Type y to get another card , Type n to pass : ") | ||
if(accept=='y'): | ||
rand=random.choice(cards) | ||
if(rand==11 and rand+player_sum>21): | ||
player_sum+=1 | ||
player.append(1) | ||
else: | ||
player_sum+=rand | ||
player.append(rand) | ||
else:break | ||
|
||
if player_sum>21: | ||
print(f"Your cards : {player} ,current score : {player_sum}") | ||
print("You Lost") | ||
exit() | ||
|
||
while computer_sum<player_sum: | ||
rand=random.choice(cards) | ||
if (rand == 11 and rand + computer_sum > 21): | ||
computer_sum += 1 | ||
computer.append(1) | ||
else: | ||
computer_sum += rand | ||
computer.append(rand) | ||
|
||
if computer_sum>21 or player_sum>computer_sum : | ||
print(f"Your cards : {player} ,Your score : {player_sum}") | ||
print(f"Computer cards : {computer} ,Computer score : {computer_sum}") | ||
|
||
print("You Won") | ||
exit() | ||
if(computer_sum==player_sum): | ||
print(f"Your cards : {player} ,Your score : {player_sum}") | ||
print(f"Computer cards : {computer} ,Computer score : {computer_sum}") | ||
|
||
print("Draw!!") | ||
exit() | ||
|
||
if(computer_sum>player_sum): | ||
print(f"Your cards : {player} ,Your score : {player_sum}") | ||
print(f"Computer cards : {computer} ,Computer score : {computer_sum}") | ||
|
||
print("You Lost") | ||
exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import random | ||
number=random.randint(1,100) | ||
|
||
|
||
def guessNUmber(number, num , level): | ||
|
||
while level!=1: | ||
if(num>number): | ||
print("Too High") | ||
else:print("Too Low") | ||
level-=1 | ||
print(f"YOU have {level} attemps left") | ||
num = int(input("Guess the number : ")) | ||
|
||
if(num==number):print(f"YOU GUESSED IT CORRECT IT WAS {num}") | ||
else:print(f"YOU GUESSED IT WRONG IT WAS {number}") | ||
|
||
print("choose the level of game 'hard' or 'easy'") | ||
level = input().lower() | ||
|
||
while True: | ||
|
||
|
||
if(level!="hard" and level!="easy"): | ||
print("Invalid Choice") | ||
else:break | ||
|
||
print("choose the level of game 'hard' or 'easy'") | ||
level = input().lower() | ||
|
||
print("I am thinking of a number betwen 1-100. \n ") | ||
num = int(input("Guess the number : ")) | ||
|
||
if level == "hard": | ||
guessNUmber(number, num, 5) | ||
elif level == "easy:": | ||
guessNUmber(number, num, 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import random | ||
|
||
stages = [''' | ||
+---+ | ||
| | | ||
O | | ||
/|\ | | ||
/ \ | | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
O | | ||
/|\ | | ||
/ | | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
O | | ||
/|\ | | ||
| | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
O | | ||
/| | | ||
| | ||
| | ||
=========''', ''' | ||
+---+ | ||
| | | ||
O | | ||
| | | ||
| | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
O | | ||
| | ||
| | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
| | ||
| | ||
| | ||
| | ||
========= | ||
'''] | ||
lives = 6 | ||
word_list = ["baboon", "delhi", "adamantium", "dehradun"] | ||
# choosing a random word from the list | ||
word = random.choice(word_list); | ||
print(f"The chosen word is {word}") | ||
blank_list = [] | ||
|
||
for i in range(len(word)): | ||
blank_list += "_" | ||
end_game=False | ||
while end_game == False: | ||
guess = input("Guess a letter\n") | ||
|
||
if guess not in word: | ||
lives=lives-1 | ||
else: | ||
for i in range(len(word)): | ||
if word[i]==guess: | ||
blank_list[i]=guess | ||
|
||
if lives==0 or "_" not in blank_list: | ||
end_game=True | ||
|
||
# Clear.clear() | ||
for i in blank_list: | ||
print(i,end=" ") | ||
print(stages[lives]) | ||
|
||
if(lives==0):print("YOU LOSE!!") | ||
else :print("YOU WON!!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#Password Generator Project | ||
import random | ||
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', | ||
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', | ||
'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', | ||
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', | ||
'W', 'X', 'Y', 'Z'] | ||
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] | ||
symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+'] | ||
|
||
print("Welcome to the PyPassword Generator!") | ||
|
||
|
||
no_letters=int(input("How many letters would you like to use in password?\n")) | ||
no_symbols=int(input("How many symbols would you like? \n")) | ||
no_numbers=int(input("How many numbers would you like? \n")) | ||
|
||
|
||
|
||
|
||
def easy_version(): | ||
password = "" | ||
for i in range(no_letters): | ||
ran=random.randint(0,len(letters)) | ||
password+=letters[ran] | ||
for i in range(no_numbers): | ||
ran=random.randint(0,len(numbers)) | ||
password+=str(numbers[ran]) | ||
for i in range(no_symbols): | ||
ran=random.randint(0,len(symbols)) | ||
password+=str(symbols[ran]) | ||
print(password) | ||
|
||
def hard_version(): | ||
password_list=[] | ||
password="" | ||
for i in range(no_letters): | ||
ran=random.randint(0,len(letters)-1) | ||
password_list+=letters[ran] | ||
for i in range(no_numbers): | ||
ran=random.randint(0,len(numbers)-1) | ||
password_list+=str(numbers[ran]) | ||
for i in range(no_symbols): | ||
ran=random.randint(0,len(symbols)-1) | ||
password_list+=str(symbols[ran]) | ||
|
||
random.shuffle(password_list) | ||
for i in password_list: | ||
password+=i | ||
|
||
print(password) | ||
|
||
|
||
hard_version() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import random | ||
|
||
randomInteger=random.randint(0,2) | ||
userInput=int(input("What do you choose ? Type 0 for Rock,1 for Paper or 2 for Scissors\n")) | ||
if(userInput!=0 and userInput!=1 and userInput!=2): | ||
print("Wrong choise") | ||
exit() | ||
|
||
if(userInput==randomInteger): | ||
print("DRAW!!!") | ||
elif (userInput==randomInteger-1 or (userInput==2 and randomInteger==0)): | ||
print("Computer Won") | ||
elif (randomInteger==userInput-1 or (randomInteger==2 and userInput==0)): | ||
print("YOU WON!!!") | ||
print(userInput) | ||
print(f"computer choose {randomInteger}") |