我想制作一个与玩家一起玩Rock,Paper,Scissors的机器人。
但每次我尝试运行脚本,并输入QTabWidget
(德语为摇滚),
if语句没有检测到它或者没有采取任何行动。
到目前为止,这是我的代码:
Stein
答案 0 :(得分:1)
>>> outcomes2 = ("Stein")
>>> print(random.choice(outcomes2))
n
您正在迭代字符串并随机选择一个字符。
我假设你想要:
>>> outcomes2 = ("Stein", )
>>> print(random.choice(outcomes2))
Stein
现在,通过指定,
,您将迭代一个字符串元组(大小为1的元组)。你最终会得到" Stein"除非您添加更多字符串,例如
outcomes2 = ("Stein", "Name2", "Name3", ...)
你想要outcomes = random.choice(outcomes2)
。不要将值赋给print
语句,因为print
返回None。
把它放在一起......
outcomes2 = ("Stein", )
Runde = 0
while True:
Player = input("Deine Wahl: ")
outcomes = random.choice(outcomes2)
if outcomes == Player:
print("draw")
Runde + 1
continue
答案 1 :(得分:-2)
`import time
import random
comp_score=0
play_score=0
outcome=('rock','paper','scissor')
while True:
player = raw_input("Enter any?");
out=random.choice(outcome)
print "COMP->"+out
if out==player:
print "draw"
elif out=="rock"and player=="scissor":
comp_score+=1;
elif out=="scissor" and player=="rock":
play_score+=1;
elif out=="rock" and player=="paper":
play_score+=1;
elif out=='paper' and player=='rock':
comp_score+=1;
elif out=="scissor" and player=="paper":
play_score+=1;
elif out=='paper' and player=="scissor":
comp_score+=1;
elif player=="quit":
break;
print "GAME over"
print "PLayer score: ",play_score
print "Comp score ",comp_score`