Bottom Page

Thread Rating:
• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Beginner Needs Help To Get On The Right Track gmom316 Unladen Swallow Posts: 2 Threads: 1 Joined: Oct 2019 Reputation: 0 Likes received: 0 #1 Oct-09-2019, 02:44 PM (This post was last modified: Oct-09-2019, 03:19 PM by ichabod801. Edited 1 time in total. Edit Reason: Python tags ) I have an intro lab assignment, due today naturally, that I'm unable to get started. We were taught the "while" repetition structures but I don't know how to do this 2 player war game. It's a mess but here's what I have and would greatly appreciate any suggestions to get me on the right track. Thanks! ```#description: generate a simulated version of the card game "War" #two player game; will need to enter each player's name #computer will generate a random number between 1-13 #the player with the highest number gets a point #if both players get the same number, it's a draw #first player to get to 10 points wins import random #initialize variables player_one = str player_two = str player_one_draw = 0 player_two_draw = 0 player_one_draw = 0 player_two_draw = 0 player_one_score = 0 player_two_score = 0 player_one_draw = random.randint(1,13) player_two_draw = random.randint(1,13) #ask for player names player_one = str(input("Enter Player one name:")) player_two = str(input("Enter Player one name:")) #while neither player has 10 points while player_one_score <10: player_one_score = str(input(player_one,"'s random number is",player_one_draw)) player_two_score = str(input(player_two,"'s random number is",player_two_draw)) if player_one_draw > player_two_draw: elif player_two_score > player_one_score: player_two_score = +1 elif player_one_draw == player_two_draw: print("Both numbers were equal") if score ==10: print(player_one,"'s score is:",player_one_score) print(player_two,"'s score is:",player_two_score) player_one_score = player_one_score + 1 print(player_one,"'s score is",player_one_score) print(player_two,"'s score is",player_two_score) ``` ichabod801 wrote Oct-09-2019, 03:19 PM:Please use python and output tags when posting code and results. I put them in for you this time. Here are instructions for doing it yourself next time. ichabod801 Bunny Rabbit Posts: 4,231 Threads: 94 Joined: Sep 2016 Reputation: 272 Likes received: 1264 #2 Oct-09-2019, 03:27 PM You need to fix the if/elif chain starting on 32. Note than an elif must have the same indentation as the 'if' it is an alternative to. It can't be on it's own level of indentation like yours are. Line 42 needs to go into that if/elif chain. I will leave it to you to figure out where. Line 29 does not match the comment on line 28. You need to add an 'and' along with another condition. See if you can figure that condition out yourself. Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures gmom316 Unladen Swallow Posts: 2 Threads: 1 Joined: Oct 2019 Reputation: 0 Likes received: 0 #3 Oct-09-2019, 03:32 PM (This post was last modified: Oct-09-2019, 03:42 PM by gmom316.) ```#description: generate a simulated version of the card game "War" #two player game; will need to enter each player's name #computer will generate a random number between 1-13 #the player with the highest number gets a point #if both players get the same number, it's a draw #first player to get to 10 points wins import random #initialize variables player_one = str player_two = str player_one_draw = random.randit (1,13) player_two_draw = random.randit (1,13) player_one_score = 0 player_two_score = 0 #ask for player names player_one = str(input("Enter Player one name:")) player_two = str(input("Enter Player one name:")) #while neither player has 10 points while player_one_score and player_two_score <10: player_one = print(player_one,"'s random number is",random.randint(1,13) player_two = print(player_two,"'s random number is",random.randint(1,13) if player_one_draw == player_two_draw: print("Both numbers were equal") player_one_score = player_one_score + 1 if score ==10: print(player_one,"'s score is:",player_one_score) print(player_two,"'s score is:",player_two_score)``` Thank you! Before you posted, this is what I was working on. I'm getting a syntax on line 26??? The output needs to show each players running score for each round until someone reaches 10 points, so I KNOW I'm still missing something vital. ichabod801 Bunny Rabbit Posts: 4,231 Threads: 94 Joined: Sep 2016 Reputation: 272 Likes received: 1264 #4 Oct-09-2019, 04:32 PM You are missing a close parenthesis on line 25. Also one on line 26. If you don't see the syntax error, always check the line before where the error occurred. Craig "Ichabod" O'Brien - xenomind.com I wish you happiness. Recommended Tutorials: BBCode, functions, classes, text adventures jefsummers Verb Conjugator Posts: 545 Threads: 1 Joined: May 2019 Reputation: 50 Likes received: 73 #5 Oct-09-2019, 06:53 PM The while loop conditions are posed wrong. Needs to be player_one_score<10 and player_two_score<10 In 25 and 26, besides the missing parentheses above, what is the result of the print, and why are you assigning the value of the print to player_one? After those statements, both of your players will be named "None" « Next Oldest | Next Newest »

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)