相关疑难解决方法(0)

文本游戏 - 将输入文本转换为小写 - Python 3.0

((针对上述编辑,上述链接未对此进行回答.上述问题与我的预期用途无关.))

我读过一个关于将字符串变成小写的类似问题;

如何在Python中将字符串转换为小写

我理解这是如何完美的,但是我自己的尝试失败了.

这是我当前调试块的设置示例;

#Debug block - Used to toggle the display of variable data throughout the game for debug purposes.
def debug():
    print("Would you like to play in Debug/Developer Mode?")
    while True:
        global egg
        choice = input()
        if choice == "yes":
            devdebug = 1
            break
        elif choice == "Yes":
            devdebug = 1
            break
        elif choice == "no":
            devdebug = 0
            break
        elif choice == "No":
            devdebug = 0
            break
        elif choice == "bunny":
            print("Easter is Here!")
            egg = …
Run Code Online (Sandbox Code Playgroud)

python text input lowercase

-1
推荐指数
1
解决办法
2万
查看次数

Python if,else语句

我已经开始自己学习python以获得乐趣,而我正在写这篇并没有得到我想要的结果:

if no1234 == 0:
     print "Player and Computer tie!\n"
elif no1234 == 1 or 2:
     print "Player wins!\n"
elif no1234 == 3 or 4:
     print "Computer wins!\n"
Run Code Online (Sandbox Code Playgroud)

计算机胜利不会出现,有什么东西我忘了

python if-statement

-2
推荐指数
1
解决办法
125
查看次数

如果字符串包含几个子字符串之一,则Python

与此处类似:Python是否具有包含子字符串方法的字符串?这个问题只处理一个字符串中的一个子字符串,我想测试几个。

就像是:

if 'AA' or 'BB' or 'CC' not in string:
    print 'Nope'
Run Code Online (Sandbox Code Playgroud)

但是,如果我的测试字符串是:

string='blahblahAA'
Run Code Online (Sandbox Code Playgroud)

if仍为True并打印该语句。我可能只是错误地理解了语法,将不胜感激。

谢谢!

python string if-statement

-2
推荐指数
1
解决办法
4727
查看次数

Python:如何使这段代码更简单?

我下面有一些代码,choice只接受整数输入,但如果输入不是整数,则输出一些特殊的代码.但是,下面的代码来处理这个问题似乎有点冗长.无论如何要解决它?

from sys import exit

def gold_room():
    print "This room is full of gold.  How much do you take?"

    choice = raw_input("> ")
    if "0" in choice or "1" in choice or "2" in choice or "3" in choice or "4" in choice or "5" in choice or "6" in choice or "7" in choice or "8" in choice or "9" in choice:
        how_much = int(choice)
    else:
        dead("Man, learn to type a number.")

    if how_much < 50:
        print …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

-2
推荐指数
1
解决办法
70
查看次数

理解Python函数

目前我有这个功能:

x = 0
limit = 10
y = 7
def basic(x):
    global y
    while x <= limit:
        if x == 0 or 1:
            y += 1
            basic(x+1)
            return x
        else:
            y += 2
            basic(x+1)
            return x

basic(x)
print(y)
Run Code Online (Sandbox Code Playgroud)

当我打印y时它返回18,这意味着它被卡在if语句中并且不会转到else语句但x确实停止在极限,因此y = 18.我在网上查找了各种来源,但我无法得到一个确切的清楚可视化我的问题.

python

-2
推荐指数
1
解决办法
57
查看次数

type(number)==(float或int)返回false python

我正在检查函数的参数是浮点数还是带有此行的int并且它保持返回false,有人可以解释为什么会发生这种情况吗?

def distance_from_zero(number):
    if type(number) == (int or float):
        return abs(number)
    else:
        return "Nope"
Run Code Online (Sandbox Code Playgroud)

python

-3
推荐指数
1
解决办法
241
查看次数

为什么这个python函数不起作用?

为什么这不起作用?

def distance_from_zero(x):        
    if type(x) == int or float:
        return abs(x) 
    else:
        return "Not an integer or float!"

print distance_from_zero(2050)
Run Code Online (Sandbox Code Playgroud)

然而,这是正确答案,这是一回事!

def distance_from_zero(x):    

    if type(x) == int or type(x) == float:
        return abs(x) 
    else:
        return "Not an integer or float!"

print distance_from_zero(2050)
Run Code Online (Sandbox Code Playgroud)

python types function

-4
推荐指数
1
解决办法
918
查看次数

IF语句(检查列表中的字符串)表现得很奇怪

这可能是一个愚蠢的问题,但为什么这段代码表现得像这样呢?

>>> test = ['aaa','bbb','ccc']
>>> if 'ddd' or 'eee' in test:
...     print True
... 
True
>>> 
Run Code Online (Sandbox Code Playgroud)

我期待stdio上没有打印任何内容,因为IF语句中的所有字符串都不在列表中.

我错过了什么吗?

python list

-5
推荐指数
1
解决办法
97
查看次数

==与Python中的运算符相对

我对python中的比较运算符有疑问.我想知道这是对还是错.

我有一些分配给变量的输出.所以我们说:

result1, result2, result3
Run Code Online (Sandbox Code Playgroud)

现在我做一个比较

if result1 == 0 and result2 == 0 and result3 == 0: 
    print "Success "
else:
    print "failure"
Run Code Online (Sandbox Code Playgroud)

我怀疑这种比较可以用这种格式进行

if 0 in (result1 , result2 ,result3):
    print "Success"
else :
    print "failure"
Run Code Online (Sandbox Code Playgroud)

这是正确使用Python吗?如果没有,那是什么原因?

python if-statement equals

-8
推荐指数
2
解决办法
359
查看次数

标签 统计

python ×9

if-statement ×3

equals ×1

function ×1

input ×1

list ×1

lowercase ×1

python-2.7 ×1

string ×1

text ×1

types ×1