小编kra*_*ind的帖子

为什么不读这个'if'语句?

在我的代码中,我希望两个答案'对立'和'斜边',有两个不同的结果,但是,每当我测试代码并回答时,'相反',它会忽略其余的代码并转到'斜边的问题.我是否将其格式化错误/是否有更简单的方法来执行此操作/等等?

from math import *

    def  main():

       #Trignometry Problem

        def answer():
            answer = raw_input()

    while True:

        # Phrase Variables
        phrase1 = ("To begin, we will solve a trigonometry problem using sin.")
        phrase2 = ("Which is known - hypotenuse or opposite?")
        phrase3 = ("Good! Now, we will begin to solve the problem!")
        phrase4 = ("Please press any key to restart the program.")

        print phrase1
        origin=input("What is the origin?")
        print phrase2
        answer = raw_input()
        if answer == ("Hypotenuse.") or ("Hypotenuse") or ("hypotenuse") …
Run Code Online (Sandbox Code Playgroud)

python

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

如何计算'for'循环内的内容?

我正在进行一项任务,我必须将一个模拟机器人在一个循环中移动到屏幕上 - 我已经将那部分放下了,但是,在循环之间,我还必须打印每个运动覆盖的区域的百分比 - 这是我的问题.

我google了一下,甚至发现有同样问题的人,但是,我不确定我是否正确地做到了.

提供此代码:

percent_complete = 0

for i in range(5):
    percent_complete += 20
    print('{}% complete'.format(percent_complete))
Run Code Online (Sandbox Code Playgroud)

然而,在发生错误之后,进一步的谷歌搜索显示只能使用某些版本

所以我使用了这段代码:

percent_complete = 0

for i in range(5):
        percent_complete += 20
        print '% complete' % (percent_complete)
Run Code Online (Sandbox Code Playgroud)

并且,至少,它现在执行代码,但是,打印时的输出如下:

Here we go!
hello
omplete
hello
(omplete
hello
<omplete
hello
Pomplete
hello
domplete
Run Code Online (Sandbox Code Playgroud)

这是什么原因?我假设因为其中一个代码必须编辑,其他部分也可以编辑,但我不确定需要做什么.

python

1
推荐指数
1
解决办法
162
查看次数

标签 统计

python ×2