473,608 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help

1 New Member
I am a kid that is taking videos on how to code in python. I am making the card game war as a project and have been stuck on a problem for weeks. if i use a dictionary to show the card suits, or the face cards, it ignores if the cards are eaqual. i dont know where the problem is, so i’ll post the entire thing. also, I am working in pycharm. I am only a 7’th grader and dont expect you to read the whole thing. thanks!

ps: if I use this,:arrow_dow n:︎ ,instead of the dictionary, the code runs without a flaw.

unconverted_dec k=[1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,1,2,3,4,5,6, 7,8,9,10,11,12, 13,14,1,2,3,4,5 ,6,7,8,9,10,11, 12,13,14,1,2,3, 4,5,6,7,8,9,10, 11,12,13,14]

here



import random
import time
test_list2 = []
test_list1 = []

unconverted_dec k = {'2❤️' : 2,
'3❤️' : 3,
'4❤️' : 4,
'5❤️' : 5,
'6❤️' : 6,
'7❤️' : 7,
'8❤️' : 8,
'9❤️' : 9,
'10❤️' : 10,
'J❤️' : 11,
'Q❤️' : 12,
'K❤️' : 13,
'A❤️' : 15,
'2♠️' : 2,
'3♠️': 3,
'4♠️': 4,
'5♠️': 5,
'6♠️': 6,
'7♠️': 7,
'8♠️': 8,
'9♠️': 9,
'10♠️': 10,
'J♠️': 11,
'Q♠️': 12,
'K♠️️': 13,
'A♠️️': 15,
'2♦️': 2,
'3♦️': 3,
'4♦️': 4,
'5♦️': 5,
'6♦️': 6,
'7♦️': 7,
'8♦️': 8,
'9♦️': 9,
'10♦️': 10,
'J♦️': 11,
'Q♦️': 12,
'K♦️': 13,
'A♦️': 15,
'2︎♣️': 2,
'3♣️': 3,
'4♣️': 4,
'5♣️': 5,
'6♣️': 6,
'7♣️': 7,
'8♣️': 8,
'9♣️': 9,
'10♣️': 10,
'J♣️': 11,
'Q♣️': 12,
'K♣️': 13,
'A♣️': 15}
oedokn = list(unconverte d_deck)
random.shuffle( oedokn)

computer_primar y = oedokn[1::2]
player_primary = oedokn[0::2]
random.shuffle( player_primary)
random.shuffle( computer_primar y)
player_secondar y = []
computer_second ary = []
turns = 5
play_card_index = 0
# ---------------------------------
print(player_pr imary)
print(computer_ primary)
comp_card_index = 0
play_war_at_ris k = []
comp_war_at_ris k = []

while winner := ' ':
play_win_round = False
comp_win_round = False
play_len = len(player_prim ary) + len(player_seco ndary)
comp_len = len(computer_pr imary) + len(computer_se condary)
print(' ')
print(' ')
ready = input("Ready?: ")
try:
if ready.lower() == "":
print("your card is: " + str(player_prim ary[play_card_index]))
print("your opponent's is: " + str(computer_pr imary[comp_card_index]))
# ------------------------------------
if player_primary[play_card_index] > computer_primar y[comp_card_index]:
player_secondar y.append(player _primary[play_card_index])
player_secondar y.append(comput er_primary[comp_card_index])
player_primary. remove(player_p rimary[play_card_index])
computer_primar y.remove(comput er_primary[comp_card_index])
print('player discard: '+str(player_se condary))
play_win_round = True
print('computer discard: [?,?,?...]')
elif player_primary[play_card_index] < computer_primar y[comp_card_index]:
computer_second ary.append(play er_primary[play_card_index])
computer_second ary.append(comp uter_primary[comp_card_index])
player_primary. remove(player_p rimary[play_card_index])
computer_primar y.remove(comput er_primary[comp_card_index])
print('player discard: '+str(player_se condary))
print('computer discard: [?,?,?...]')
comp_win_round = True
elif play_win_round or comp_win_round == False:
while len(comp_war_at _risk) < 4:
play_war_at_ris k.append(player _primary[play_card_index])
player_primary. remove(player_p rimary[play_card_index])
comp_war_at_ris k.append(comput er_primary[comp_card_index])
computer_primar y.remove(comput er_primary[comp_card_index])
# ------------------------------------
print('player cards at risk: '+str(play_war_ at_risk))
print('computer cards at risk: [?,?,?...]'
print(' ')
input("⚔️ Ready for war⚔️?: ")
print(' ')
print("your card is: " + str(player_prim ary[play_card_index]))
print("your opponent's is: " + str(computer_pr imary[comp_card_index]))
# ------------------------------------
if player_primary[play_card_index] > computer_primar y[comp_card_index]:
player_secondar y.append(player _primary[play_card_index])
player_secondar y.append(comput er_primary[comp_card_index])
player_primary. remove(player_p rimary[play_card_index])

# ------------------------------------------
player_secondar y.append(play_w ar_at_risk[0])
player_secondar y.append(play_w ar_at_risk[1])
player_secondar y.append(play_w ar_at_risk[2])
player_secondar y.append(play_w ar_at_risk[3])
# -------------------------------------------
player_secondar y.append(comp_w ar_at_risk[0])
player_secondar y.append(comp_w ar_at_risk[1])
player_secondar y.append(comp_w ar_at_risk[2])
player_secondar y.append(comp_w ar_at_risk[3])
# -------------------------------------------
play_war_at_ris k.clear()
comp_war_at_ris k.clear()
# -------------------------------------------
computer_primar y.remove(comput er_primary[comp_card_index])
print('player discard: ' + str(player_seco ndary))
print('computer discard: [?,?,?...]')
# -------------------------------------------
elif player_primary[play_card_index] < computer_primar y[comp_card_index]:
computer_second ary.append(play er_primary[play_card_index])
computer_second ary.append(comp uter_primary[comp_card_index])
player_primary. remove(player_p rimary[play_card_index])
computer_primar y.remove(comput er_primary[comp_card_index])
# --------------------------------------------
computer_second ary.append(play _war_at_risk[0])
computer_second ary.append(play _war_at_risk[1])
computer_second ary.append(play _war_at_risk[2])
computer_second ary.append(play _war_at_risk[3])
# -------------------------------------------
computer_second ary.append(comp _war_at_risk[0])
computer_second ary.append(comp _war_at_risk[1])
computer_second ary.append(comp _war_at_risk[2])
computer_second ary.append(comp _war_at_risk[3])
# -------------------------------------------
play_war_at_ris k.clear()
comp_war_at_ris k.clear()
print('player discard: ' + str(player_seco ndary))
print('computer discard: [?,?,?...]')
elif player_primary[play_card_index] == computer_primar y[comp_card_index]:
while len(comp_war_at _risk) < 4:
play_war_at_ris k.append(player _primary[play_card_index])
player_primary. remove(player_p rimary[play_card_index])
comp_war_at_ris k.append(comput er_primary[comp_card_index])
computer_primar y.remove(comput er_primary[comp_card_index])
print(play_war_ at_risk)
print(comp_war_ at_risk)
print('your at risk = ' + str(play_war_at _risk))
print('COMP at risk = '+ str(comp_war_at _risk))
print(' ')
print(' ')
ready = input("⚔️ Ready for war⚔️?: ")
except IndexError:
for u in computer_second ary:
computer_primar y.append(u)
random.shuffle( computer_primar y)
for i in player_secondar y:
player_primary. append(i)
random.shuffle( player_primary)
computer_second ary.clear()
player_secondar y.clear()
print(' new round ')
print(' good luck')
print(' 👍🏻👍🏻👍🏻👍🏻 👍🏻')
print(' 🤘🏻😁🤘🏻😁🤘🏻 ')
print(' ')
print(' ')
print(' ')
print(' ')
print(' ')
turns=turns+1
if play_len == 0:
for e in player_secondar y:
player_primary. append(e)
print('end of the game!')
print('the winner is...')
print('💣🧨💣🧨')
print(5)
time.sleep(1)
print(4)
time.sleep(1)
print(3)
time.sleep(1)
print(2)
time.sleep(1)
print(1)
time.sleep(1)
print('💥💥 you 💥💥')
break
elif comp_len == 0:
for e in computer_second ary:
computer_primar y.append(e)
print('end of the game!')
print('the winner is...')
print('💣🧨💣🧨')
print(5)
time.sleep(1)
print(4)
time.sleep(1)
print(3)
time.sleep(1)
print(2)
time.sleep(1)
print(1)
time.sleep(1)
print('💥💥 computer 💥💥')
break
Sep 19 '22 #1
1 10749
dev7060
644 Recognized Expert Contributor
I am a kid that is taking videos on how to code in python. I am making the card game war as a project and have been stuck on a problem for weeks. if i use a dictionary to show the card suits, or the face cards, it ignores if the cards are eaqual. i dont know where the problem is, so i’ll post the entire thing. also, I am working in pycharm. I am only a 7’th grader and dont expect you to read the whole thing. thanks!

ps: if I use this,:arrow_dow n:︎ ,instead of the dictionary, the code runs without a flaw.

unconverted_dec k=[1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,1,2,3,4,5,6, 7,8,9 ,10,11,12,13,14 ,1,2,3,4,5,6,7, 8,9,10,11,12,13 ,14,1 ,2,3,4,5,6,7,8, 9,10,11,12,13,1 4]
Post the code with proper indentations and use [code] tags.
Oct 4 '22 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
6524
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to reformatting my system. Prior to the reformatting, I copied the help.rtf file onto a CD and checked the box to...
6
4323
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing result in any way. Who can help me, I thank you very very much. list.cpp(main program) //-------------------------------------------------------------------------- - #pragma hdrstop #pragma argsused
3
3343
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With numarray, help gives unhelpful responses:
7
5361
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not most, keywords. Is there any way I can activate these "missing" help topics? HELP!
5
3256
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects: the DLL and a tester. VB does not look for my help file; instead, it looks for path to my source code...
9
2240
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help for your progs? Whats the current popular approach to creating help? I am only wanting a straight help file accessible from a menu - no context sensitive stuff. TIA
8
3215
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both including search the internet for help, but the help is worthless. Any ideas?
3
2024
by: lord.zoltar | last post by:
I've managed to get a nice little chm help system written. Now I need to display it! I added a HelpProvider to my MDIParent form and set the namespace of the HelpProvider to be the help file. So far so good - when I press F1, I get HTML Help popping up with my Help file. This is good but I've been requested to make Help pop up when the user clicks on "Help" in the menu, or on a specific Help Button. I'm trying to trigger the HelpRequested...
10
3349
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably the worst I ever seen. I almost cannot find anything I need, including things I
0
2869
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in case of Help, I see the Help of Excel and help of my application, both as a submenu of help. ...
0
8067
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8010
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8501
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8483
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4030
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1336
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.