Python中的一般结构

时间:2017-09-30 20:24:43

标签: python

我是面向对象语言的新手(多年来在VBA中编程)并且很难切换到它(没有母语为英语的人......对即将到来的错误感到抱歉)

这是我的第一个程序,我想测试不同的东西。运行我的VSC调试器我在第7行收到错误(文件:'file:///c%3A/python/test.py'严重性:'Fehler'消息:'E0001:预期缩进块(第7行)' )。但我认为这是一个更普遍的问题。一般结构好吗?首先导入,然后定义2个函数?

先谢谢你帮助我!

import ctypes
import random

def main():
    rndNumber = random.randint(0, 10)
    MBoxString = "is this a good Number? "+ rndNumber
    Mbox("Number", MBoxString, 1)
    varContinue = int(input("1 for yes & 2 for no! "))
    while varContinue == 2:
        rndNumber = random.randint(0, 10)
        print("Is this a better one?", rndNumber)
        varContinue = int(input("1 for yes & 2 for no! "))



def Mbox(title, text, style):
    return ctypes.windll.user32.MessageBoxW(0, text, title, style)

1 个答案:

答案 0 :(得分:1)

以下代码有效: 所做的更改:

MBoxString = "is this a good Number? "+ str(rndNumber)

代码:

import ctypes
import random

def main():
    rndNumber = random.randint(0, 10)
    MBoxString = "is this a good Number? "+ str(rndNumber)
    Mbox("Number", MBoxString, 1)
    varContinue = int(input("1 for yes & 2 for no! "))
    while varContinue == 2:
        rndNumber = random.randint(0, 10)
        print("Is this a better one?", rndNumber)
        varContinue = int(input("1 for yes & 2 for no! "))

def Mbox(title, text, style):
    return ctypes.windll.user32.MessageBoxW(0, text, title, style)

main()