在Visual Studio 2013中断言Python 3.6中的语法 [英] Assert syntax in Python 3.6 within visual studio 2013

查看:101
本文介绍了在Visual Studio 2013中断言Python 3.6中的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了YouTube初学者视频中使用的简单程序。代码在这里给出:

 来自 math  import  sin,cos,radians 
import sys

def make_dot_string(x):
return ' ' * int( 10 * cos(radians(x))+ 10 )+ < span class =code-string>' o'

断言make_dot_string( 90 )== ' o'
断言make_dot_string( 180 )== ' o'

def main():
for i 范围内e( 10000000 ):
s = make_dot_string(i)
print (s)

如果 __name __ == __ main __
sys.exit(int(main() 0 ))



问题是断言语句。它们与视频完全相同,但我的编译器会挂起它们。 感谢任何想法。



我尝试过:



我已经搜索了python和visual studio文档,但是这个问题显然被认为是微不足道的,它还没有解决我遇到的任何问题。 Microsoft VS 2015确实解决了python,但VS 2013似乎没有这样做。

解决方案

当我运行你的Python程序时,我得到了一个AssertionError。我认为这就是'我的编译器挂起它们'的意思(作为旁注,Python不是编译而是解释)。 AssertionError意味着'这个断言是假的'。 make_dot_string(90)显然等于'            o'因为它等于'             &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;○'。我不知道你想做什么以及预期的输出应该是什么,所以只有你可以弄清楚它是否是错误的断言,或者 make_dot_string 这个函数是错误的。


在Python shell中正常工作。唯一的问题是 make_dot_string 函数返回值,应该是:

  return  ' ' * int( 10  * cos(弧度(x))+  10 )+ '  o'  开头的字符串应该是单个空格。 


I worked through a simple program used in a YouTube beginners video. The code is given here:

from math import sin,cos, radians
import sys

def make_dot_string(x):
    return '  '*int(10*cos(radians(x))+10) + 'o'

assert make_dot_string(90) ==   '          o'
assert make_dot_string(180) ==  'o'

def main():
    for i in range(10000000):
        s = make_dot_string(i)
        print(s)

    if __name__== "__main__":
        sys.exit(int(main() or 0))


The problem is the assert statements. They are identical to the video, but my compiler hangs up on them. Any thoughts are appreciated.

What I have tried:

I have searched the python and visual studio documentation, but this issue apparently is considered so trivial it is not addressed in anything I have come across yet. Microsoft VS 2015 does address python, but VS 2013 does not appear to do so.

解决方案

When I ran your Python program, I got an AssertionError. I assume this is what you mean by 'my compiler hangs up on them' (as a side note, Python is not compiled but interpreted). An AssertionError means 'this assertion was false'. make_dot_string(90) was apparently not equal to '          o' because it's equal to '                    o'. I don't know what you want to do and what the expected output should be, so only you can figure out if it's the assertion that's wrong, or the make_dot_string function that's wrong.


Works fine in the Python shell. Only problem is the make_dot_string function return value, should be:

return ' '*int(10*cos(radians(x))+10) + 'o' # the string at the beginning should be a single space.


这篇关于在Visual Studio 2013中断言Python 3.6中的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆