自学作业出错了。 (蟒蛇)

时间:2013-07-26 17:40:19

标签: python python-3.x

Word1 = input("Please type a word: ")
Word2 = input("Please type a word: ")
if len(Word1) + len(Word2)> 30:
    print("Words are to long")
    # exit -- Gotten rid of.
30 - (len(Word1) + len(Word2) == DotAmount
 print (Word1 + "."*DotAmount + Word2) # This line is causing the problem

我似乎无法解决这个问题。 有人想帮忙吗?

编辑:此程序要求用户输入2个单词,然后在它们之间打印带点符号(。),以便打印30个字符。 如果有人有更好的方法来编写这个程序,请随意添加它。 通过CMD打开错误

SyntaxError: invalid syntax

指针指向打印。

2 个答案:

答案 0 :(得分:5)

我假设您要分配

的值
30 - (len(Word1) + len(Word2)) ## note that you were also missing a closing paren

到名称DotAmount

执行此操作的python语法是

 name = value

所以你想要

DotAmount =  30 - (len(Word1) + len(Word2))

有关信息,a == b会检查a是否等于b并返回TrueFalse,在这种情况下会被丢弃。< / p>

答案 1 :(得分:0)

这是你想要的吗?

例如,如果Word1 = "test1"Word2 = "test2" 输出 test1....................test2

import sys
Word1 = input("Please type a word: ")
Word2 = input("Please type a word: ")
if len(Word1) + len(Word2)> 30:
    print("Words are to long")
    # exit -- Gotten rid of.
    sys.exit()

sDots = "." * (30 - len(Word1) - len(Word2))
print(Word1 + sDots + Word2)