u/Fun-Pitch-6938

Hello, everyone, I would like to know how you can do this in python more dynamically. I was able to do it but i had to copy and paste the powers repeatedly to get the result needed. I would assume you would need 2 loops in the list comprehension but i dont know how to.

"""


Using list comprehension create the following list of tuples:




[(0, 1, 0, 0, 0, 0, 0),
(1, 1, 1, 1, 1, 1, 1),
(2, 1, 2, 4, 8, 16, 32),
(3, 1, 3, 9, 27, 81, 243),
(4, 1, 4, 16, 64, 256, 1024),
(5, 1, 5, 25, 125, 625, 3125),
(6, 1, 6, 36, 216, 1296, 7776),
(7, 1, 7, 49, 343, 2401, 16807),
(8, 1, 8, 64, 512, 4096, 32768),
(9, 1, 9, 81, 729, 6561, 59049),
(10, 1, 10, 100, 1000, 10000, 100000)]


"""





lst = [(x, 1, x, x**2, x**3,x**4,x**5  )for x in range(0,11)]


print(lst)
reddit.com
u/Fun-Pitch-6938 — 4 days ago

Hello, i am a python beginner / learner and i just created a function that lets the user play rock, paper, scissors vs the computer (randomly generated). The code works, but i would like to know what are people's thoughts on it. What are some things that i might've done that seem redundant or could be done a better way?

TLDR, give me your thoughts / reviews on it, what it good / isn't, etc...

Thanks in advance.

Code:

"""

make the computer keep track of how many times user gets wins (correct) vs how many times it got it correct (it wins)

"""

import random

Outcomes = {
    "R ls P": "Paper beats rock",
    "R bts S": "Rock beats Scissors",
    # Rock section

    "S bts P": "Scissors beats paper"
    # Paper section

}


def rock_paper_scissors():
    my_score = 0
    comp_score = 0

    for i in range(0, 3):
        options = ['Rock', 'Paper', 'Scissors']

        computers_choice = random.choice(options)

        my_choice = input("Enter either Rock, Paper, Or Scissors: ").capitalize()

        print(f"The computer picked: {computers_choice}")


        if computers_choice == my_choice:
            print("Even Score: 0, No one wins.... ")

        elif computers_choice == 'Rock':
            if my_choice == 'Paper':
                outcome = Outcomes.get("R ls P")
                print(f"The outcome is {outcome}, You win! ")
                my_score += 1
                print(f"Your total score is {my_score}")

            else:
                outcome = Outcomes.get("R bts S")
                print(f"The outcome is {outcome}, The computer wins! ")
                comp_score += 1
                print(f"The computer's total score is {comp_score}")


        elif computers_choice == 'Paper':
            if my_choice == 'Rock':
                outcome = Outcomes.get("R ls P")
                print(f"The outcome is {outcome}, The computer wins! ")
                comp_score += 1
                print(f"The computer's total score is {comp_score}")

            elif my_choice == 'Scissors':
                outcome = Outcomes.get("S bts P")
                print(f"The outcome is {outcome}, you win!")
                my_score += 1
                print(f"Your total score is {my_score}")


        else:
            if my_choice == 'Rock':
                outcome = Outcomes.get("R bts S")
                print(f"The outcome is {outcome}, you win!")
                my_score += 1
                print(f"Your total score is {my_score}")

            else:
                outcome = Outcomes.get("S bts P")
                print(f"The outcome is {outcome}, the computer wins! ")
                comp_score += 1
                print(f"The computer's total score is {comp_score}")

        print()

    print(f"Your score is {my_score}")
    print(f"Computer score is {comp_score}")


rock_paper_scissors()
reddit.com
u/Fun-Pitch-6938 — 15 days ago