不返回else值 [英] Doesnt return the else value
本文介绍了不返回else值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了代码问题。到目前为止,这是我得到的。
im having a problem with a code. so far, here's what i got.
import random
p = 0
mace = random.randint(5,9)
katana = random.randint(12,20)
club = random.randint(8,15)
bandage = random.randint(15,25)
medkit = random.randint(30,55)
painkillers = random.randint(7,16)
player_health = 100
equip = mace
items = {bandage,medkit}
zombie = 100
print '\nSo, Which way shall you go?'
direction = raw_input('Left or Right: ')
#player is in either location 1 or 2
if direction == 'Left' or 'left':
p = p + 1
print p
else:
p = p + 2
print p
它似乎没有返回值2当我输入单词Right。我忘记了什么吗?感谢您的帮助:D
我的尝试:
if和elif,else和doble ifs。
it doesnt seem to return the value 2 when i input the word Right. am i forgetting something? thanks for the help :D
What I have tried:
if and elif, else and doble ifs.
推荐答案
尝试
try
if direction == 'Left' or direction == 'left':
或运算符的工作方式为:表达式1或表达式2
另一种方法是在测试前将方向转换为大写。
the or operator work as: expression 1 or expression 2
Another way is to convert direction to uppercase before testing.
这篇关于不返回else值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文