New in Pyscript, please spare any dumb mistakes.
Wrote a simple rock-paper-scissor game as below and to run through web browser. It is running fine, but what I need is that in the prompt it asks the user as "Enter r for rock, p for paper and s for scissor:" instead of blank as in the below screenshot.
I tried python.write, but somehow it throws error and not sure how to use it. Any guidance is much appreciated.
<HTML>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<py-script>
import random
gameAttribute = ['rock','paper','scissor']
count=0
yourChoice=0
comChoice=0
print('==============================================================')
print('Welcome','Welcome to ROCK-PAPER-SCISSOR game, Come and try your luck!')
print('==============================================================')
while(count != 5):
count += 1
random_choice = (random.choices(gameAttribute))
computerMove = random_choice[0]
#print(random.choice(random_choice))
yourMove = input('Enter r for rock, p for paper and s for scissor:')
if yourMove == 'r':
yourMove = 'rock'
elif yourMove == 'p':
yourMove = 'paper'
elif yourMove == 's':
yourMove ='scissor'
else:
print("Choose between the given choice only!")
print('computer move: {} '.format(computerMove))
print("Your move:", yourMove)
if yourMove == computerMove:
print("It's a tie!\n")
elif yourMove == 'rock' and computerMove == 'paper':
comChoice += 1
print('You lose!\n')
elif yourMove == 'rock' and computerMove == 'scissor':
yourChoice += 1
print('You Win!\n')
elif yourMove == 'paper' and computerMove == 'rock':
yourChoice += 1
print('You Win!\n')
elif yourMove == 'paper' and computerMove == 'scissor':
comChoice += 1
print ('You lose!\n')
elif yourMove == 'scissor' and computerMove == 'paper':
yourChoice += 1
print('you Win!\n')
elif yourMove == 'scissor' and computerMove == 'rock':
comChoice += 1
print('You lose!\n')
else:
print('Invalid choice made!, choose between r,s,p only \n')
print('==============================================================')
if yourChoice > comChoice:
print('Congratulations! You have won the game')
elif comChoice > yourChoice:
print('You have lost the game.Better luck next time!')
elif yourChoice == comChoice:
print('Tough Competition! It is a tie')
print('==============================================================')
</py-script> </body>
</html>

Probably it's more elegant to use a
HTML formto ask the user for inputs. I just importedbulmafor nicer elements. Additionally there is a bug already reported covering you issue.Out: