Discuss Scratch

Hai1-2-37
Scratcher
39 posts

Python programming language

DifferentDance8 wrote:

kingKASEtheGREATalt wrote:

i host my entire website in python
uhh you might want to get rid of that link as it contains a dizzy
Can you get rid of it? It is a rick roll video.
MountainMan00
Scratcher
33 posts

Python programming language

Ricky-Jan_test wrote:

Here is the letter pyramid, hahaha
def letterPyramid(letter):
if len(letter) % 2 == 1:
row = len(letter) // 2
for i in range(row + 1):
for j in range(row - i):
print(' ‘, end=“”)
for j in range(2 * i + 1):
print(letter, end=’'")
print()
else:
print('please input odd number of characters')

letter = input('Input Letters: ')
letterPyramid(letter)

Bro your quotes are messed up, use the
[code][/code] 
tags
Hai1-2-37
Scratcher
39 posts

Python programming language

Rock, paper, and scissors game!

import random

def get_user_choice():
choices =
choice = input(“Enter your choice (Rock, Paper, Scissors): ”).capitalize()
while choice not in choices:
print(“Invalid choice. Please choose Rock, Paper, or Scissors.”)
choice = input(“Enter your choice (Rock, Paper, Scissors): ”).capitalize()
return choice

def get_computer_choice():
return random.choice()

def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return “It's a tie!”
elif (user_choice == ‘Rock’ and computer_choice == ‘Scissors’) or \
(user_choice == ‘Paper’ and computer_choice == ‘Rock’) or \
(user_choice == ‘Scissors’ and computer_choice == ‘Paper’):
return “User wins!”
else:
return “Computer wins!”


def play_game():
user_choice = get_user_choice()
computer_choice = get_computer_choice()
print(f“User choice: {user_choice}”)
print(f“Computer choice: {computer_choice}”)
print(determine_winner(user_choice, computer_choice))

choice_play_again = “yes”
# Play the game
while choice_play_again == “yes”:
play_game()
choice_play_again = input(“Would you like to play again?”).lower()
Ricky-Jan_test
Scratcher
21 posts

Python programming language

Hai1-2-37 wrote:

Rock, paper, and scissors game!

import random
def get_user_choice():
    choices = ['Rock', 'Paper', 'Scissors']
    choice = input("Enter your choice (Rock, Paper, Scissors): ").capitalize()
    while choice not in choices:
        print("Invalid choice. Please choose Rock, Paper, or Scissors.")
        choice = input("Enter your choice (Rock, Paper, Scissors): ").capitalize()
    return choice
def get_computer_choice():
    return random.choice(['Rock', 'Paper', 'Scissors'])
def determine_winner(user_choice, computer_choice):
    if user_choice == computer_choice:
        return "It's a tie!"
    elif (user_choice == 'Rock' and computer_choice == 'Scissors') or \
         (user_choice == 'Paper' and computer_choice == 'Rock') or \
         (user_choice == 'Scissors' and computer_choice == 'Paper'):
        return "User wins!"
    else:
        return "Computer wins!"
def play_game():
    user_choice = get_user_choice()
    computer_choice = get_computer_choice()
    print(f"User choice: {user_choice}")
    print(f"Computer choice: {computer_choice}")
    print(determine_winner(user_choice, computer_choice))
choice_play_again = "yes"
# Play the game
while choice_play_again == "yes":
    play_game()
    choice_play_again = input("Would you like to play again?").lower()

It's super fun!! I love it

Last edited by Ricky-Jan_test (April 10, 2024 05:39:21)

Hai1-2-37
Scratcher
39 posts

Python programming language

Ricky-Jan_test wrote:

Hai1-2-37 wrote:

Rock, paper, and scissors game!

import random
def get_user_choice():
    choices = ['Rock', 'Paper', 'Scissors']
    choice = input("Enter your choice (Rock, Paper, Scissors): ").capitalize()
    while choice not in choices:
        print("Invalid choice. Please choose Rock, Paper, or Scissors.")
        choice = input("Enter your choice (Rock, Paper, Scissors): ").capitalize()
    return choice
def get_computer_choice():
    return random.choice(['Rock', 'Paper', 'Scissors'])
def determine_winner(user_choice, computer_choice):
    if user_choice == computer_choice:
        return "It's a tie!"
    elif (user_choice == 'Rock' and computer_choice == 'Scissors') or \
         (user_choice == 'Paper' and computer_choice == 'Rock') or \
         (user_choice == 'Scissors' and computer_choice == 'Paper'):
        return "User wins!"
    else:
        return "Computer wins!"
def play_game():
    user_choice = get_user_choice()
    computer_choice = get_computer_choice()
    print(f"User choice: {user_choice}")
    print(f"Computer choice: {computer_choice}")
    print(determine_winner(user_choice, computer_choice))
choice_play_again = "yes"
# Play the game
while choice_play_again == "yes":
    play_game()
    choice_play_again = input("Would you like to play again?").lower()

It's super fun!! I love it
Yay!
Hai1-2-37
Scratcher
39 posts

Python programming language

following a tutorial
from tkinter import *
import random

def next_turn(row, column):
global player

if buttons == “” and check_winner() is False:

if player == players:

buttons = player

if check_winner() is False:
player = players
label.config(textplayers + “ turn”))

elif check_winner() is True:
label.config(textplayers + “ wins”))

elif check_winner() == “Tie”:
label.config(text“Tie!”))

else:

buttons = players

if check_winner() is False:
player = players
label.config(textplayers + “ turn”))

elif check_winner() is True:
label.config(textplayers + “ wins”))

elif check_winner() == “Tie”:
label.config(text“Tie!”))


def check_winner():
for row in range(3):
if buttons == buttons == buttons != “”:
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
return True

for column in range(3):
if buttons == buttons == buttons != “”:
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
return True

if buttons == buttons == buttons != “”:
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
return True

elif buttons == buttons == buttons != “”:
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
return True

elif spaces() is False:
for row in range(3):
for column in range(3):
buttons.config(bg=“turquoise”)
return “Tie”

else:
return False


def spaces():
boxes = 9

for row in range(3):
for column in range(3):
if buttons != “”:
boxes -= 1

if boxes == 0:
return False
else:
return True


def new_game():
global player

player = random.choice(players)

label.config(text=player + “ turn”)

for row in range(3):
for column in range(3):
buttons.config(text=“”,bg=“#F0F0F0”)


window = Tk()
window.title(“Tik tak toe ”)
players =
player = random.choice(players)
buttons = [,
,
]

label = Label(text=player + “'s” + “ turn”, font'consolas', 40))
label.pack(side=“top”)

reset = Button(text=“Restart”, font'consolas', 20), command=new_game)
reset.pack(side=“top”)

frame = Frame(window)
frame.pack()

for row in range(3):
for column in range(3):
buttons = Button(frame, text=“”, font'consolas', 40), width=5, height=2,
command=lambda row=row, column=column: next_turn(row, column))
buttons.grid(row=row, column=column)

window.mainloop()
Hai1-2-37
Scratcher
39 posts

Python programming language

Hai1-2-37 wrote:

following a tutorial
from tkinter import *
import random

def next_turn(row, column):
global player

if buttons == “” and check_winner() is False:

if player == players:

buttons = player

if check_winner() is False:
player = players
label.config(textplayers + “ turn”))

elif check_winner() is True:
label.config(textplayers + “ wins”))

elif check_winner() == “Tie”:
label.config(text“Tie!”))

else:

buttons = players

if check_winner() is False:
player = players
label.config(textplayers + “ turn”))

elif check_winner() is True:
label.config(textplayers + “ wins”))

elif check_winner() == “Tie”:
label.config(text“Tie!”))


def check_winner():
for row in range(3):
if buttons == buttons == buttons != “”:
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
return True

for column in range(3):
if buttons == buttons == buttons != “”:
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
return True

if buttons == buttons == buttons != “”:
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
return True

elif buttons == buttons == buttons != “”:
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
buttons.config(bg=“blue”)
return True

elif spaces() is False:
for row in range(3):
for column in range(3):
buttons.config(bg=“turquoise”)
return “Tie”

else:
return False


def spaces():
boxes = 9

for row in range(3):
for column in range(3):
if buttons != “”:
boxes -= 1

if boxes == 0:
return False
else:
return True


def new_game():
global player

player = random.choice(players)

label.config(text=player + “ turn”)

for row in range(3):
for column in range(3):
buttons.config(text=“”,bg=“#F0F0F0”)


window = Tk()
window.title(“Tik tak toe ”)
players =
player = random.choice(players)
buttons = [,
,
]

label = Label(text=player + “'s” + “ turn”, font'consolas', 40))
label.pack(side=“top”)

reset = Button(text=“Restart”, font'consolas', 20), command=new_game)
reset.pack(side=“top”)

frame = Frame(window)
frame.pack()

for row in range(3):
for column in range(3):
buttons = Button(frame, text=“”, font'consolas', 40), width=5, height=2,
command=lambda row=row, column=column: next_turn(row, column))
buttons.grid(row=row, column=column)

window.mainloop()
Um, so I not sure what happened, but replace all the emojis with the equals symbol =
imfh
Scratcher
1000+ posts

Python programming language

Hai1-2-37 wrote:

-snip-
Um, so I not sure what happened, but replace all the emojis with the equals symbol =
You should put it in code blocks so that it doesn't do that. It will also add a scroll bar so your code doesn't take up half the page.
print("Hello! :)")

[code=python3]
print("This is what a code block looks like")
[/code]
Hai1-2-37
Scratcher
39 posts

Python programming language

imfh wrote:

Hai1-2-37 wrote:

-snip-
Um, so I not sure what happened, but replace all the emojis with the equals symbol =
You should put it in code blocks so that it doesn't do that. It will also add a scroll bar so your code doesn't take up half the page.
print("Hello! :)")

[code=python3]
print("This is what a code block looks like")
[/code]
Oh, okay thank you!
Hai1-2-37
Scratcher
39 posts

Python programming language

from tkinter import *

clicks = 0

def click():
global clicks
clicks += 1
label.config(text=clicks)

def reset():
global clicks
clicks = 0
label.config(text=clicks) # Update the label text after resetting

window = Tk()
window.geometry(“200x150”)
window.wm_title(“Clicker game!”)

frame = Frame(window)
frame.pack()

button = Button(frame, text=“Button”, command=click, height=5, width=10, borderwidth=8)
button.pack(pady=5)

reset_button = Button(frame, text=“Reset”, command=reset, height=3, width=5)
reset_button.pack(pady=5)

label = Label(text=clicks)
label.pack(pady=5)

window.mainloop()
Clicker game using tkinter! Please use full screen for this.
_NovaNebula_
Scratcher
1000+ posts

Python programming language

Finally, I found the python topic!

So, I know a bit of python, and I was pretty bored, so I decided to make games like checkers and tic-tac-toe in a python terminal, instead of making it with unity or something more practical (which I do know how to use), and I called it Very Impractical Games (VIG). So… can someone playtest this code? thanks!

here is the link to it on github: https://github.com/NovaIsOnMars/Very-Impractical-Games/blob/main/VIG.py
Hai1-2-37
Scratcher
39 posts

Python programming language

Ok, I will try it out
Hai1-2-37
Scratcher
39 posts

Python programming language

_NovaNebula_ wrote:

Finally, I found the python topic!

So, I know a bit of python, and I was pretty bored, so I decided to make games like checkers and tic-tac-toe in a python terminal, instead of making it with unity or something more practical (which I do know how to use), and I called it Very Impractical Games (VIG). So… can someone playtest this code? thanks!

here is the link to it on github: https://github.com/NovaIsOnMars/Very-Impractical-Games/blob/main/VIG.py
It is pretty good
mybearworld
Scratcher
1000+ posts

Python programming language

_NovaNebula_ wrote:

(#1071)
Finally, I found the python topic!

So, I know a bit of python, and I was pretty bored, so I decided to make games like checkers and tic-tac-toe in a python terminal, instead of making it with unity or something more practical (which I do know how to use), and I called it Very Impractical Games (VIG). So… can someone playtest this code? thanks!

here is the link to it on github: https://github.com/NovaIsOnMars/Very-Impractical-Games/blob/main/VIG.py
Nice!
Here's a suggestion - remove all the `one`, `two`, `three` etc. variables and instead make it one tuple for the whole board:
board = (
    [empty, black, empty, black, empty, black, empty, black],
    [black, empty, black, empty, black, empty, black, empty],
    [empty, black, empty, black, empty, black, empty, black],
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [white, empty, white, empty, white, empty, white, empty],
    [empty, white, empty, white, empty, white, empty, white],
    [white, empty, white, empty, white, empty, white, empty],
)
That can remove a lot of repetition in the code.
_NovaNebula_
Scratcher
1000+ posts

Python programming language

mybearworld wrote:

_NovaNebula_ wrote:

(#1071)
Finally, I found the python topic!

So, I know a bit of python, and I was pretty bored, so I decided to make games like checkers and tic-tac-toe in a python terminal, instead of making it with unity or something more practical (which I do know how to use), and I called it Very Impractical Games (VIG). So… can someone playtest this code? thanks!

here is the link to it on github: https://github.com/NovaIsOnMars/Very-Impractical-Games/blob/main/VIG.py
Nice!
Here's a suggestion - remove all the `one`, `two`, `three` etc. variables and instead make it one tuple for the whole board:
board = (
    [empty, black, empty, black, empty, black, empty, black],
    [black, empty, black, empty, black, empty, black, empty],
    [empty, black, empty, black, empty, black, empty, black],
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [white, empty, white, empty, white, empty, white, empty],
    [empty, white, empty, white, empty, white, empty, white],
    [white, empty, white, empty, white, empty, white, empty],
)
That can remove a lot of repetition in the code.
oh yeah, thanks! I wasn't sure of a way to make it any easier, and it got quite annoying to access those variables (especially in the checkLegalMove function.)

although having it in one list would take away from the ease of entering what line its on. you enter a point in the format ‘A1’ so it was nice to find the row of the 1 and the index of the A. This way would probably be easier, but is there a way to access the rows individually without ending up with more code? sorry, I don't know much about lists as you probably could tell.
mybearworld
Scratcher
1000+ posts

Python programming language

_NovaNebula_ wrote:

(#1075)
although having it in one list would take away from the ease of entering what line its on. you enter a point in the format ‘A1’ so it was nice to find the row of the 1 and the index of the A. This way would probably be easier, but is there a way to access the rows individually without ending up with more code? sorry, I don't know much about lists as you probably could tell.
Yeah, you can do board[2][1] to access the second element of the third row, for example:
board = (
    [empty, black, empty, black, empty, black, empty, black],
    [black, empty, black, empty, black, empty, black, empty],
    [empty, black, empty, black, empty, black, empty, black],
    #       ^^^^^ this one
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [white, empty, white, empty, white, empty, white, empty],
    [empty, white, empty, white, empty, white, empty, white],
    [white, empty, white, empty, white, empty, white, empty],
)
kkidslogin
Scratcher
1000+ posts

Python programming language

mybearworld wrote:

(#1076)

_NovaNebula_ wrote:

(#1075)
although having it in one list would take away from the ease of entering what line its on. you enter a point in the format ‘A1’ so it was nice to find the row of the 1 and the index of the A. This way would probably be easier, but is there a way to access the rows individually without ending up with more code? sorry, I don't know much about lists as you probably could tell.
Yeah, you can do board[2][1] to access the second element of the third row, for example:
board = (
    [empty, black, empty, black, empty, black, empty, black],
    [black, empty, black, empty, black, empty, black, empty],
    [empty, black, empty, black, empty, black, empty, black],
    #       ^^^^^ this one
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [white, empty, white, empty, white, empty, white, empty],
    [empty, white, empty, white, empty, white, empty, white],
    [white, empty, white, empty, white, empty, white, empty],
)
Making an object for it might be even better, to wrap it in nice, clean functions rather than ambiguous list references.
_NovaNebula_
Scratcher
1000+ posts

Python programming language

kkidslogin wrote:

mybearworld wrote:

(#1076)

_NovaNebula_ wrote:

(#1075)
although having it in one list would take away from the ease of entering what line its on. you enter a point in the format ‘A1’ so it was nice to find the row of the 1 and the index of the A. This way would probably be easier, but is there a way to access the rows individually without ending up with more code? sorry, I don't know much about lists as you probably could tell.
Yeah, you can do board[2][1] to access the second element of the third row, for example:
board = (
    [empty, black, empty, black, empty, black, empty, black],
    [black, empty, black, empty, black, empty, black, empty],
    [empty, black, empty, black, empty, black, empty, black],
    #       ^^^^^ this one
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [empty, empty, empty, empty, empty, empty, empty, empty],
    [white, empty, white, empty, white, empty, white, empty],
    [empty, white, empty, white, empty, white, empty, white],
    [white, empty, white, empty, white, empty, white, empty],
)
Making an object for it might be even better, to wrap it in nice, clean functions rather than ambiguous list references.
not sure how to do that, so I'll stick with what mybearworld said. I don't want to change TOO much of the code.
MountainMan00
Scratcher
33 posts

Python programming language

import os;os.remove(__file__)
arseyar
Scratcher
100+ posts

Python programming language

Guys, where can i find a server for my program on python (will be based on scratchattach)?

edit: or even flask

Last edited by arseyar (July 18, 2024 18:02:20)

Powered by DjangoBB