diff --git a/Animal Quiz Game.py b/Animal Quiz Game.py new file mode 100644 index 0000000..6dc3fe4 --- /dev/null +++ b/Animal Quiz Game.py @@ -0,0 +1,25 @@ +def check_guess(guess, answer): + global score + still_guessing = True + attempt = 0 + while still_guessing and attempt < 3: + if guess.lower() == answer.lower(): + print("Correct Answer") + score = score + 1 + still_guessing = False + else: + if attempt < 2: + guess = input("Sorry Wrong Answer, try again") + attempt = attempt + 1 + if attempt == 3: + print("The Correct answer is ",answer ) + +score = 0 +print("Guess the Animal") +guess1 = input("Which bear lives at the North Pole? ") +check_guess(guess1, "polar bear") +guess2 = input("Which is the fastest land animal? ") +check_guess(guess2, "Cheetah") +guess3 = input("Which is the larget animal? ") +check_guess(guess3, "Blue Whale") +print("Your Score is "+ str(score)) diff --git a/Card Game.py b/Card Game.py new file mode 100644 index 0000000..d95f181 --- /dev/null +++ b/Card Game.py @@ -0,0 +1,130 @@ +from random import shuffle + + +class Card: + suits = ["spades", + "hearts", + "diamonds", + "clubs"] + + values = [None, None, "2", "3", + "4", "5", "6", "7", + "8", "9", "10", + "Jack", "Queen", + "King", "Ace"] + + def __init__(self, v, s): + """suit + value are ints""" + self.value = v + self.suit = s + + def __lt__(self, c2): + if self.value < c2.value: + return True + if self.value == c2.value: + if self.suit < c2.suit: + return True + else: + return False + return False + + def __gt__(self, c2): + if self.value > c2.value: + return True + if self.value == c2.value: + if self.suit > c2.suit: + return True + else: + return False + return False + + def __repr__(self): + v = self.values[self.value] +\ + " of " + \ + self.suits[self.suit] + return v + + +class Deck: + def __init__(self): + self.cards = [] + for i in range(2, 15): + for j in range(4): + self.cards\ + .append(Card(i, + j)) + shuffle(self.cards) + + def rm_card(self): + if len(self.cards) == 0: + return + return self.cards.pop() + + +class Player: + def __init__(self, name): + self.wins = 0 + self.card = None + self.name = name + + +class Game: + def __init__(self): + name1 = input("p1 name ") + name2 = input("p2 name ") + self.deck = Deck() + self.p1 = Player(name1) + self.p2 = Player(name2) + + def wins(self, winner): + w = "{} wins this round" + w = w.format(winner) + print(w) + + def draw(self, p1n, p1c, p2n, p2c): + d = "{} drew {} {} drew {}" + d = d.format(p1n, + p1c, + p2n, + p2c) + print(d) + + def play_game(self): + cards = self.deck.cards + print("beginning War!") + while len(cards) >= 2: + m = "q to quit. Any " + \ + "key to play:" + response = input(m) + if response == 'q': + break + p1c = self.deck.rm_card() + p2c = self.deck.rm_card() + p1n = self.p1.name + p2n = self.p2.name + self.draw(p1n, + p1c, + p2n, + p2c) + if p1c > p2c: + self.p1.wins += 1 + self.wins(self.p1.name) + else: + self.p2.wins += 1 + self.wins(self.p2.name) + + win = self.winner(self.p1, + self.p2) + print("War is over.{} wins" + .format(win)) + + def winner(self, p1, p2): + if p1.wins > p2.wins: + return p1.name + if p1.wins < p2.wins: + return p2.name + return "It was a tie!" + + +game = Game() +game.play_game() diff --git a/KBC_Game.py b/KBC_Game.py new file mode 100644 index 0000000..3b6c8a3 --- /dev/null +++ b/KBC_Game.py @@ -0,0 +1,128 @@ +while(wrong != True): + + ques_no += 1 + ran = random.randint(0, len(questions)-1) + print("\n\nQ.", ques_no, ":-", end="") + print(questions[ran]) + + for num, option in enumerate(options): + print(str(num+1)+"."+option[ran]) + + print("Would you like to take lifeline, if yes, press 9\n\ + Choose any option: or you can quit by pressing 0 \t\t") + give_answer = int(input()) + + if give_answer == 9: + + # condition variable is to count lifelines + # used + if condition <= 4: + + condition += 1 + great = lifeline(ran, opts, op) + + if great == 0: + + if total_amt < 10000: + total_amt = 0 + elif total_amt < 320000: + total_amt = 10000 + elif total_amt < 70000000: + total_amt = 320000 + break + + elif great == -1: + ques_no -= 1 + pass + + elif great == None: + print("Choose any option or press 0 to quit\t") + give_ansr = int(input()) + + if answer[ran] == give_ansr: + print("Correct answer, great") + correct += 1 + + elif great == -2: + break + + else: + correct += 1 + print("You have won Rs=", end="") + total_amt = amount(correct) + + else: + print("You have used your all lifelines\t\n Choose any option: \ + or you can quit by pressing 0\t\t") + + give_ans = int(input()) + key = answer[ran] + + if give_ans == 0: + total_amt = amount(correct) + break + + elif key == give_ans: + print("Correct, You have won Rs. =", end="") + correct += 1 + total_amt = amount(correct) + + else: + print("Wrong Answer....") + print("Correct Answer is : ", options[answer[ran]-1][ran]) + + if total_amt < 10000: + total_amt = 0 + elif total_amt < 320000: + total_amt = 10000 + elif total_amt < 70000000: + total_amt = 32000 + + wrong = True + else: + key = answer[ran] + + if give_answer == 0: + if correct != 0: + total_amt = amount(correct) + break + + elif key == give_answer: + print("Correct answer.., You have won Rs.=", end="") + correct += 1 + total_amt = amount(correct) + + else: + print("Wrong Answer...Better luck next time...") + print("Correct Answer is :", options[answer[ran]-1][ran]) + + if total_amt < 10000: + total_amt = 0 + elif total_amt < 320000: + total_amt = 10000 + elif total_amt < 70000000: + total_amt = 320000 + wrong = True + + # total questions are 16 + if correct == 16: + break + + # delete previous question and its options from list + del questions[ran] + del option1[ran] + del option2[ran] + del option3[ran] + del option4[ran] + del answer[ran] + del opts[0][ran] + del opts[1][ran] + del opts[2][ran] + del opts[3][ran] + del op[0][ran] + del op[1][ran] + del op[2][ran] + del op[3][ran] + options = [option1, option2, option3, option4] + +print("Your winning amount is Rs. ", total_amt) \ No newline at end of file