[英]If statement does not detect string or doesn't take action
我想做一个与玩家玩摇滚,剪纸,剪刀的机器人。 但是,每次我尝试运行该脚本并输入Stein
(德语为Rock)时,if语句都不会检测到该脚本或不执行任何操作。
到目前为止,这是我的代码:
import random
import time
print("Anfangs Buchstaben immer groß schreiben!")
time.sleep(2)
outcomes2 = ("Stein")
Runde = 0
while True:
Player = input("Deine Wahl: ")
for i in range(1):
outcomes = print(random.choice(outcomes2))
if outcomes == Player:
print("draw")
Runde + 1
continue
>>> 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
`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`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.