Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » Python programming language
- Hai1-2-37
-
Scratcher
39 posts
Python programming language
Can you get rid of it? It is a rick roll video.i host my entire website in pythonuhh you might want to get rid of that link as it contains a dizzy
- MountainMan00
-
Scratcher
33 posts
Python programming language
Here is the letter pyramid, hahahadef 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]
- 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()
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
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
Rock, paper, and scissors game!Yay!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
- 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(text
players + “ turn”))
elif check_winner() is True:
label.config(text
players + “ wins”))
elif check_winner() == “Tie”:
label.config(text
“Tie!”))
else:
buttons = players
if check_winner() is False:
player = players
label.config(text
players + “ turn”))
elif check_winner() is True:
label.config(text
players + “ 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()
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(text
players + “ turn”))elif check_winner() is True:
label.config(text
players + “ wins”))elif check_winner() == “Tie”:
label.config(text
“Tie!”))else:
buttons = players
if check_winner() is False:
player = players
label.config(text
players + “ turn”))elif check_winner() is True:
label.config(text
players + “ 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
following a tutorialUm, so I not sure what happened, but replace all the emojis with the equals symbol =
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()
- imfh
-
Scratcher
1000+ posts
Python programming language
-snip-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.
Um, so I not sure what happened, but replace all the emojis with the equals symbol =

print("Hello! :)")
[code=python3] print("This is what a code block looks like") [/code]
- Hai1-2-37
-
Scratcher
39 posts
Python programming language
Oh, okay thank you!-snip-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.
Um, so I not sure what happened, but replace all the emojis with the equals symbol =print("Hello! :)")[code=python3] print("This is what a code block looks like") [/code]
- 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.
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.

#1071May 2, 2024 00:49:10
- _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
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
#1072May 2, 2024 04:19:01
#1073May 4, 2024 03:54:41
- Hai1-2-37
-
Scratcher
39 posts
Python programming language
Finally, I found the python topic!It is pretty good
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
#1074May 4, 2024 06:58:40
- mybearworld
-
Scratcher
1000+ posts
Python programming language
(#1071)Nice!
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
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], )
#1075May 4, 2024 10:48:17
- _NovaNebula_
-
Scratcher
1000+ posts
Python programming language
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.)(#1071)Nice!
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
Here's a suggestion - remove all the `one`, `two`, `three` etc. variables and instead make it one tuple for the whole board:That can remove a lot of repetition in the code.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], )
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.
#1076May 4, 2024 10:54:47
- mybearworld
-
Scratcher
1000+ posts
Python programming language
(#1075)Yeah, you can do board[2][1] to access the second element of the third row, for example:
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.
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], )
#1077May 4, 2024 14:37:57
- kkidslogin
-
Scratcher
1000+ posts
Python programming language
(#1076)Making an object for it might be even better, to wrap it in nice, clean functions rather than ambiguous list references.(#1075)Yeah, you can do board[2][1] to access the second element of the third row, for example:
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.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], )
#1078May 6, 2024 00:28:07
- _NovaNebula_
-
Scratcher
1000+ posts
Python programming language
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.(#1076)Making an object for it might be even better, to wrap it in nice, clean functions rather than ambiguous list references.(#1075)Yeah, you can do board[2][1] to access the second element of the third row, for example:
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.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], )
- 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
edit: or even flask
Last edited by arseyar (July 18, 2024 18:02:20)
- Discussion Forums
- » Things I'm Making and Creating
-
» Python programming language








