石剪,剪刀-大写或小写

  • 本文关键字:剪刀 石剪 python python-3.x
  • 更新时间 :
  • 英文 :


我的任务是为Rock,Paper,Scissors游戏创建用户输入。

我能够得到正确的输出结果,输入所有小写的输入。但是,如果其中一个或两个(除非它们是相同的输入(都是大写的,我不会得到打印语句。

我将如何使用.upper().lower()来确保代码按预期运行?

P1 = input('Enter [R]ock, [P]aper, or [S]cissor' )
print ('Player 1:', P1)
P2 = input('Enter [R]ock, [P]aper, or [S]cissor' )
print ('Player 2:', P2)
if P1 == P2 :
print('Nobody WINS!')
elif P1 == 's' :
if P2 == 'r' :
print('Rock smashes scissors.')
print('P2 WINS!')
else :
print('Scissor cuts paper.')
print('P1 WINS!')
elif P1 == 'r' :
if P2 == 'p' :
print('Paper covers rock.')
print('P2 WINS!')
else :
print('Rock smashes scissors.')
print('P1 WINS!')
elif P1 == 'p' :
if P2 == 's' :
print('Scissor cuts paper.')
print('P2 WINS!')
else :
print('Paper covers rock.')
print('P1 WINS!')`P1 = input('Enter [R]ock, [P]aper, or [S]cissor' )
P1 = input('Enter [R]ock, [P]aper, or [S]cissor' ).lower()
print ('Player 1:', P1)
P2 = input('Enter [R]ock, [P]aper, or [S]cissor' ).lower()
print ('Player 2:', P2)

如果用户输入了一个大写字母,通过执行上面的操作,它将变为小写。。。

最新更新