SlideShare a Scribd company logo
1 of 6
Download to read offline
Help fix this code. Exploding kittens card came in python.
import random
# --------------------------------------------------------------------------------------------------------------------------------
------------
# SET UP
# create deck
deck = ['see the future'] * 5 + ['attack'] * 4 + ['skip'] * 4 + ['favor'] * 4 + ['nope'] * 5 +
['shuffle'] * 4 + ['taco cat'] * 4 + ['harry potato cat'] * 4 + ['beard cat'] * 4 + ['catermelon'] * 4 +
['rainbow ralphing cat'] * 4
# dealing a card from the deck
def deal_card(deck):
return deck.pop()
# adding a card to a hand
def add_card_to_hand(hand, card):
hand.append(card)
# function to draw a card from the deck
def draw_card(deck):
if deck:
return deck.pop(0)
else:
return None
# shuffle the deck
random.shuffle(deck)
# Welcome message
print("nWelcome to Exploding Kittens!n")
# ask user for how many players
num_players = int(input("nThere can be 2-5 players. How many players will be playing?n"))
# Check if the number of players is between 2 and 5
while num_players < 2 or num_players > 5:
print("Invalid number of players.")
num_players = int(input("nThere can be 2-5 players. How many players will be playing?n"))
if num_players < 2 or num_players > 5:
print("nInvalid optionn")
else:
players = []
for i in range(num_players):
player = {
"id": i + 1,
"hand": [],
"active": True,
"lives": 1
}
players.append(player)
# adding a defuse card to each player's hand
for j in range(1):
add_card_to_hand(player["hand"], 'defuse')
# dealing 7 more cards to each player
for j in range(7):
card = deal_card(deck)
add_card_to_hand(player["hand"], card)
# adding exploding kittens back into the deck based on num_players
for i in range(num_players - 1):
deck.append('exploding kitten')
# adding defuse back into the deck based on num_players
if num_players == 2 or num_players == 3 or num_players == 4:
deck.append('defuse')
deck.append('defuse')
elif num_players == 5:
deck.append('defuse')
# shuffle the deck
random.shuffle(deck)
# --------------------------------------------------------------------------------------------------------------------------------
------------
# CARDS
# ATTACK
def attack(player_hands, player_num, deck):
# ask the current player who they want to attack
target_num = int(input("Who do you want to attack?"))
# make the attacked player draw two cards from the deck
for i in range(2):
card = draw_card(deck)
if card == "exploding kitten":
if "defuse" in player_hands[target_num]:
# the attacked player has a defuse card
print(f"Player {target_num} drew an exploding kitten but defused it!")
player_hands[target_num].remove("defuse")
# reinsert the exploding kitten card back into the deck
deck.insert(random.randint(0, len(deck)), "exploding kitten")
else:
# the attacked player doesn't have a defuse card and is out of the game
print(f"Player {target_num} drew an exploding kitten and is out of the game.")
else:
add_card_to_hand(player_hands[target_num], card)
print(f"Player {target_num} has drawn 2 cards from the deck.")
# FAVOR
def favor(player_hands, player_num):
# get the list of players' ids except for the current player
player_ids = [p['id'] for p in players if p['id'] != player_num]
# check if there are any other players
if not player_ids:
print("There are no other players to take a card from.")
return
# ask the current player which player they want to take a card from
print("Which player would you like to take a card from?")
for i, pid in enumerate(player_ids):
print(f"{i+1}. Player {pid}")
choice = int(input()) - 1
# get the chosen player's hand
chosen_player_hand = player_hands[player_ids[choice] - 1]
# check if the chosen player has any cards
if not chosen_player_hand:
print(f"Player {player_ids[choice]} has no cards to take.")
return
# choose a random card from the chosen player's hand
card_to_take = random.choice(chosen_player_hand)
chosen_player_hand.remove(card_to_take)
# add the card to the current player's hand
add_card_to_hand(player_hands[player_num-1], card_to_take)
print(f"You took '{card_to_take}' from player {player_ids[choice]}.")
# SEE THE FUTURE
def see_the_future(player_hands, player_num, pick_card, deck):
# Check if the card is in the player's hand
if len(deck) > 3:
print("The card '{0}' has been removed from player {1}'s hand.".format(pick_card, player_num))
# Display the top three cards
print("nThe top three cards of the deck are:n")
# last three numbers in the array is really where player will draw from
for i in range(-1, -4, -1):
print(deck[i])
# check if deck has three cards to diplay
else:
print("There are not three cards to view in the deck")
# SKIP
def skip(player_num, pick_card, player_hands):
print("Turn skipped.n")
# SHUFFLE
def shuffle_fun(deck, player, players):
random.shuffle(deck)
print("The deck has been shuffled.n")
# CAT CARDS
def cat_cards(deck, player, players):
print ("cat card")
# --------------------------------------------------------------------------------------------------------------------------------
------------
# GAME PLAY
# until there is only one player left
while len([p for p in players if p['active']]) > 1:
# iterate over all players
for player in players:
# skip inactive players
if not player['active']:
continue
# display player's hand
print("nPlayer {0}, here is your hand:".format(player['id']))
for card in player['hand']:
print(card)
# prompt user how many cards they want to play
num_cards = int(input("nPlayer {0}, how many cards do you want to play? (0 to
pass)n".format(player['id'])))
# play cards
for i in range(num_cards):
# prompt user to choose a card
card_name = input("nChoose a card to play:n")
# check if card is in player's hand
if card_name not in player['hand']:
print("You do not have {0} in your hand.".format(card_name))
continue
elif card_name == "attack":
attack('player_hands', 'player_num', deck)
elif card_name == "favor":
favor('player_hands', 'player_num', 'pick_card', deck)
elif card_name == "skip":
skip('player_num', 'pick_card', 'player_hands')
elif card_name == "shuffle":
shuffle_fun(deck, player, players)
elif card_name == "see the future":
see_the_future('player_hands', 'player_num', 'pick_card', deck)
elif card_name == "taco cat" or card_name == "beard cat" or card_name == "catermelon" or
card_name == "rainbow ralphing cat" or card_name == "harry potato cat":
cat_cards(deck, player, players)
player['hand'].remove(card_name)
if card_name != 'skip' or card_name != 'attack':
# draw card
card = draw_card(deck)
add_card_to_hand(player['hand'], card)
if card == 'exploding kitten':
if 'defuse' in player['hand']:
print ("You drew an exploding kitten, but you had a defuse to save you!")
# discard defuse
player['hand'].remove('defuse')
# place exploding kitten back into the deck at a random spot
index = random.randint(0, len(deck))
deck.insert(index, 'exploding kitten')
# remove exploding kitten from hand
player['hand'].remove('exploding kitten')
else:
print("Oh no! You drew an exploding kitten and lost a life.")
player_status[player_num-1] = False
print("You're out of the game!")
# get list of active players
active_players = [p for p in players if p['active']]
# check if only one active player left
if len(active_players) == 1:
# get the active player
active_player = [p for p in players if p['active']][0]
print("Player {0} wins!".format(active_player['id']))
else:
print("You drew a {0}.".format(card))
# draw a card if the player chose to pass
if num_cards == 0:
card = draw_card(deck)
add_card_to_hand(player['hand'], card)
if card == 'exploding kitten':
if 'defuse' in player['hand']:
print ("You drew an exploding kitten, but you had a defuse to save you!")
# discard defuse
player['hand'].remove('defuse')
# place exploding kitten back into the deck at a random spot
index = random.randint(0, len(deck))
deck.insert(index, 'exploding kitten')
# remove exploding kitten from hand
player['hand'].remove('exploding kitten')
else:
print("Oh no! You drew an exploding kitten and lost a life.")
player_status[player_num-1] = False
print("You're out of the game!")
# get list of active players
active_players = [p for p in players if p['active']]
# check if only one active player left
if len(active_players) == 1:
# get the active player
active_player = [p for p in players if p['active']][0]
print("Player {0} wins!".format(active_player['id']))
else:
print("You drew a {0}.".format(card))
print ("Game Over!")

More Related Content

Similar to Help fix this code Exploding kittens card came in python .pdf

#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
aquapariwar
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
eyelineoptics
 
Please use java to write the program that simulates the card game!!! T (1).pdf
Please use java to write the program that simulates the card game!!! T (1).pdfPlease use java to write the program that simulates the card game!!! T (1).pdf
Please use java to write the program that simulates the card game!!! T (1).pdf
admin463580
 
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docxThere are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
AustinIKkNorthy
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
asif1401
 
#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf
singhanubhav1234
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
info430661
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
feelinggifts
 

Similar to Help fix this code Exploding kittens card came in python .pdf (14)

#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
 
Code em Poker
Code em PokerCode em Poker
Code em Poker
 
AI For Texam Hold'em poker
AI For Texam Hold'em pokerAI For Texam Hold'em poker
AI For Texam Hold'em poker
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
Please use java to write the program that simulates the card game!!! T (1).pdf
Please use java to write the program that simulates the card game!!! T (1).pdfPlease use java to write the program that simulates the card game!!! T (1).pdf
Please use java to write the program that simulates the card game!!! T (1).pdf
 
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
 
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docxThere are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
 
Bouncingballs sh
Bouncingballs shBouncingballs sh
Bouncingballs sh
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
TicketBEKA? Ticket booking
TicketBEKA? Ticket bookingTicketBEKA? Ticket booking
TicketBEKA? Ticket booking
 
#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf#include stdio.h #include string.h #include stdlib.h #in.pdf
#include stdio.h #include string.h #include stdlib.h #in.pdf
 
Card Games in C++
Card Games in C++Card Games in C++
Card Games in C++
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 

More from geetakannupillai1

Highlight the correct answer i have tried myself Pleas.pdf
Highlight the correct answer   i have tried myself   Pleas.pdfHighlight the correct answer   i have tried myself   Pleas.pdf
Highlight the correct answer i have tried myself Pleas.pdf
geetakannupillai1
 
Hi Im currently working on my python assignment and Im st.pdf
Hi Im currently working on my python assignment and Im st.pdfHi Im currently working on my python assignment and Im st.pdf
Hi Im currently working on my python assignment and Im st.pdf
geetakannupillai1
 
hhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdf
hhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdfhhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdf
hhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdf
geetakannupillai1
 
Here is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdf
Here is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdfHere is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdf
Here is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdf
geetakannupillai1
 
Here is two discussion board posts please give me a paragrap.pdf
Here is two discussion board posts please give me a paragrap.pdfHere is two discussion board posts please give me a paragrap.pdf
Here is two discussion board posts please give me a paragrap.pdf
geetakannupillai1
 
here is the starter code public class LinkedListPracticeLab.pdf
here is the starter code public class LinkedListPracticeLab.pdfhere is the starter code public class LinkedListPracticeLab.pdf
here is the starter code public class LinkedListPracticeLab.pdf
geetakannupillai1
 
Here is The code in C language .pdf
Here is The code in C language  .pdfHere is The code in C language  .pdf
Here is The code in C language .pdf
geetakannupillai1
 

More from geetakannupillai1 (20)

Hidrojen ba bir elektropozitif hidrojen H atomunun civ.pdf
Hidrojen ba bir elektropozitif hidrojen H atomunun civ.pdfHidrojen ba bir elektropozitif hidrojen H atomunun civ.pdf
Hidrojen ba bir elektropozitif hidrojen H atomunun civ.pdf
 
Hi In SE and under use case diagram we have 4 relationships.pdf
Hi In SE and under use case diagram we have 4 relationships.pdfHi In SE and under use case diagram we have 4 relationships.pdf
Hi In SE and under use case diagram we have 4 relationships.pdf
 
Highlight the correct answer i have tried myself Pleas.pdf
Highlight the correct answer   i have tried myself   Pleas.pdfHighlight the correct answer   i have tried myself   Pleas.pdf
Highlight the correct answer i have tried myself Pleas.pdf
 
High involvement and low involvement marketing Point Di.pdf
High involvement and low involvement marketing Point  Di.pdfHigh involvement and low involvement marketing Point  Di.pdf
High involvement and low involvement marketing Point Di.pdf
 
Hi there Can you help me determine the sample and the popul.pdf
Hi there Can you help me determine the sample and the popul.pdfHi there Can you help me determine the sample and the popul.pdf
Hi there Can you help me determine the sample and the popul.pdf
 
help please Please respond to this post by choosing any o.pdf
help please  Please respond to this post by choosing any o.pdfhelp please  Please respond to this post by choosing any o.pdf
help please Please respond to this post by choosing any o.pdf
 
Hi There Please help me with 1 The python code AND .pdf
Hi There   Please help me with 1 The python code  AND .pdfHi There   Please help me with 1 The python code  AND .pdf
Hi There Please help me with 1 The python code AND .pdf
 
Hi Im currently working on my python assignment and Im st.pdf
Hi Im currently working on my python assignment and Im st.pdfHi Im currently working on my python assignment and Im st.pdf
Hi Im currently working on my python assignment and Im st.pdf
 
Hi I need help with just step c of this question The rest.pdf
Hi I need help with just step c of this question The rest.pdfHi I need help with just step c of this question The rest.pdf
Hi I need help with just step c of this question The rest.pdf
 
Hi Experts Could some one please explain with a practical e.pdf
Hi Experts  Could some one please explain with a practical e.pdfHi Experts  Could some one please explain with a practical e.pdf
Hi Experts Could some one please explain with a practical e.pdf
 
hhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdf
hhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdfhhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdf
hhmi Biolnteractive Inheritance and Mutations in a SingleGe.pdf
 
Heteraride st ynetimin rol Soru seenekleri 1 kat.pdf
Heteraride st ynetimin rol  Soru seenekleri    1  kat.pdfHeteraride st ynetimin rol  Soru seenekleri    1  kat.pdf
Heteraride st ynetimin rol Soru seenekleri 1 kat.pdf
 
Herzbergs twofactor theory proposes that A lower wages w.pdf
Herzbergs twofactor theory proposes that A lower wages w.pdfHerzbergs twofactor theory proposes that A lower wages w.pdf
Herzbergs twofactor theory proposes that A lower wages w.pdf
 
Herhangi iki i A tr Elektronik Ticarete Girite Kutz tara.pdf
Herhangi iki i A tr Elektronik Ticarete Girite Kutz tara.pdfHerhangi iki i A tr Elektronik Ticarete Girite Kutz tara.pdf
Herhangi iki i A tr Elektronik Ticarete Girite Kutz tara.pdf
 
Help with media assessment In April 2022 WarnerMedia Owne.pdf
Help with media assessment In April 2022 WarnerMedia Owne.pdfHelp with media assessment In April 2022 WarnerMedia Owne.pdf
Help with media assessment In April 2022 WarnerMedia Owne.pdf
 
Here is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdf
Here is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdfHere is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdf
Here is support files a3_birthdaylibh ifndef A3_Q1_H defi.pdf
 
Here is two discussion board posts please give me a paragrap.pdf
Here is two discussion board posts please give me a paragrap.pdfHere is two discussion board posts please give me a paragrap.pdf
Here is two discussion board posts please give me a paragrap.pdf
 
here is the starter code public class LinkedListPracticeLab.pdf
here is the starter code public class LinkedListPracticeLab.pdfhere is the starter code public class LinkedListPracticeLab.pdf
here is the starter code public class LinkedListPracticeLab.pdf
 
Here is The code in C language .pdf
Here is The code in C language  .pdfHere is The code in C language  .pdf
Here is The code in C language .pdf
 
Helper T cells with a mutation called CCR5 delta 32 cannot .pdf
Helper T cells with a mutation called CCR5 delta 32 cannot .pdfHelper T cells with a mutation called CCR5 delta 32 cannot .pdf
Helper T cells with a mutation called CCR5 delta 32 cannot .pdf
 

Recently uploaded

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Help fix this code Exploding kittens card came in python .pdf

  • 1. Help fix this code. Exploding kittens card came in python. import random # -------------------------------------------------------------------------------------------------------------------------------- ------------ # SET UP # create deck deck = ['see the future'] * 5 + ['attack'] * 4 + ['skip'] * 4 + ['favor'] * 4 + ['nope'] * 5 + ['shuffle'] * 4 + ['taco cat'] * 4 + ['harry potato cat'] * 4 + ['beard cat'] * 4 + ['catermelon'] * 4 + ['rainbow ralphing cat'] * 4 # dealing a card from the deck def deal_card(deck): return deck.pop() # adding a card to a hand def add_card_to_hand(hand, card): hand.append(card) # function to draw a card from the deck def draw_card(deck): if deck: return deck.pop(0) else: return None # shuffle the deck random.shuffle(deck) # Welcome message print("nWelcome to Exploding Kittens!n") # ask user for how many players num_players = int(input("nThere can be 2-5 players. How many players will be playing?n")) # Check if the number of players is between 2 and 5 while num_players < 2 or num_players > 5: print("Invalid number of players.") num_players = int(input("nThere can be 2-5 players. How many players will be playing?n")) if num_players < 2 or num_players > 5: print("nInvalid optionn") else: players = [] for i in range(num_players): player = { "id": i + 1, "hand": [], "active": True, "lives": 1 }
  • 2. players.append(player) # adding a defuse card to each player's hand for j in range(1): add_card_to_hand(player["hand"], 'defuse') # dealing 7 more cards to each player for j in range(7): card = deal_card(deck) add_card_to_hand(player["hand"], card) # adding exploding kittens back into the deck based on num_players for i in range(num_players - 1): deck.append('exploding kitten') # adding defuse back into the deck based on num_players if num_players == 2 or num_players == 3 or num_players == 4: deck.append('defuse') deck.append('defuse') elif num_players == 5: deck.append('defuse') # shuffle the deck random.shuffle(deck) # -------------------------------------------------------------------------------------------------------------------------------- ------------ # CARDS # ATTACK def attack(player_hands, player_num, deck): # ask the current player who they want to attack target_num = int(input("Who do you want to attack?")) # make the attacked player draw two cards from the deck for i in range(2): card = draw_card(deck) if card == "exploding kitten": if "defuse" in player_hands[target_num]: # the attacked player has a defuse card print(f"Player {target_num} drew an exploding kitten but defused it!") player_hands[target_num].remove("defuse") # reinsert the exploding kitten card back into the deck deck.insert(random.randint(0, len(deck)), "exploding kitten") else: # the attacked player doesn't have a defuse card and is out of the game print(f"Player {target_num} drew an exploding kitten and is out of the game.") else: add_card_to_hand(player_hands[target_num], card) print(f"Player {target_num} has drawn 2 cards from the deck.")
  • 3. # FAVOR def favor(player_hands, player_num): # get the list of players' ids except for the current player player_ids = [p['id'] for p in players if p['id'] != player_num] # check if there are any other players if not player_ids: print("There are no other players to take a card from.") return # ask the current player which player they want to take a card from print("Which player would you like to take a card from?") for i, pid in enumerate(player_ids): print(f"{i+1}. Player {pid}") choice = int(input()) - 1 # get the chosen player's hand chosen_player_hand = player_hands[player_ids[choice] - 1] # check if the chosen player has any cards if not chosen_player_hand: print(f"Player {player_ids[choice]} has no cards to take.") return # choose a random card from the chosen player's hand card_to_take = random.choice(chosen_player_hand) chosen_player_hand.remove(card_to_take) # add the card to the current player's hand add_card_to_hand(player_hands[player_num-1], card_to_take) print(f"You took '{card_to_take}' from player {player_ids[choice]}.") # SEE THE FUTURE def see_the_future(player_hands, player_num, pick_card, deck): # Check if the card is in the player's hand if len(deck) > 3: print("The card '{0}' has been removed from player {1}'s hand.".format(pick_card, player_num)) # Display the top three cards print("nThe top three cards of the deck are:n") # last three numbers in the array is really where player will draw from for i in range(-1, -4, -1): print(deck[i]) # check if deck has three cards to diplay else: print("There are not three cards to view in the deck") # SKIP def skip(player_num, pick_card, player_hands): print("Turn skipped.n") # SHUFFLE
  • 4. def shuffle_fun(deck, player, players): random.shuffle(deck) print("The deck has been shuffled.n") # CAT CARDS def cat_cards(deck, player, players): print ("cat card") # -------------------------------------------------------------------------------------------------------------------------------- ------------ # GAME PLAY # until there is only one player left while len([p for p in players if p['active']]) > 1: # iterate over all players for player in players: # skip inactive players if not player['active']: continue # display player's hand print("nPlayer {0}, here is your hand:".format(player['id'])) for card in player['hand']: print(card) # prompt user how many cards they want to play num_cards = int(input("nPlayer {0}, how many cards do you want to play? (0 to pass)n".format(player['id']))) # play cards for i in range(num_cards): # prompt user to choose a card card_name = input("nChoose a card to play:n") # check if card is in player's hand if card_name not in player['hand']: print("You do not have {0} in your hand.".format(card_name)) continue elif card_name == "attack": attack('player_hands', 'player_num', deck) elif card_name == "favor": favor('player_hands', 'player_num', 'pick_card', deck) elif card_name == "skip": skip('player_num', 'pick_card', 'player_hands') elif card_name == "shuffle": shuffle_fun(deck, player, players) elif card_name == "see the future": see_the_future('player_hands', 'player_num', 'pick_card', deck) elif card_name == "taco cat" or card_name == "beard cat" or card_name == "catermelon" or
  • 5. card_name == "rainbow ralphing cat" or card_name == "harry potato cat": cat_cards(deck, player, players) player['hand'].remove(card_name) if card_name != 'skip' or card_name != 'attack': # draw card card = draw_card(deck) add_card_to_hand(player['hand'], card) if card == 'exploding kitten': if 'defuse' in player['hand']: print ("You drew an exploding kitten, but you had a defuse to save you!") # discard defuse player['hand'].remove('defuse') # place exploding kitten back into the deck at a random spot index = random.randint(0, len(deck)) deck.insert(index, 'exploding kitten') # remove exploding kitten from hand player['hand'].remove('exploding kitten') else: print("Oh no! You drew an exploding kitten and lost a life.") player_status[player_num-1] = False print("You're out of the game!") # get list of active players active_players = [p for p in players if p['active']] # check if only one active player left if len(active_players) == 1: # get the active player active_player = [p for p in players if p['active']][0] print("Player {0} wins!".format(active_player['id'])) else: print("You drew a {0}.".format(card)) # draw a card if the player chose to pass if num_cards == 0: card = draw_card(deck) add_card_to_hand(player['hand'], card) if card == 'exploding kitten': if 'defuse' in player['hand']: print ("You drew an exploding kitten, but you had a defuse to save you!") # discard defuse player['hand'].remove('defuse') # place exploding kitten back into the deck at a random spot index = random.randint(0, len(deck)) deck.insert(index, 'exploding kitten')
  • 6. # remove exploding kitten from hand player['hand'].remove('exploding kitten') else: print("Oh no! You drew an exploding kitten and lost a life.") player_status[player_num-1] = False print("You're out of the game!") # get list of active players active_players = [p for p in players if p['active']] # check if only one active player left if len(active_players) == 1: # get the active player active_player = [p for p in players if p['active']][0] print("Player {0} wins!".format(active_player['id'])) else: print("You drew a {0}.".format(card)) print ("Game Over!")