Python Forum
Beginner Needs Help To Get On The Right Track
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner Needs Help To Get On The Right Track
#1
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)
Reply
#2
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
Reply
#3
#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??? Wall Wall Wall

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.
Reply
#4
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
Reply
#5
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"
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020