Python 任务2有一些问题吗

Python 任务2有一些问题吗,python,python-2.7,Python,Python 2.7,我刚刚用Python完成了我的程序,但是任务2有一些问题。您的代码有缩进问题 此外,代码中使用的变量未使用默认值定义 我在代码顶部定义了所有变量的默认值 请参阅下面的代码 #Loop starts here # This one provides the option to select one of the three tasks. task = input (' Hello! Welcome to Patricia G. Myrons program s

我刚刚用Python完成了我的程序,但是任务2有一些问题。

您的代码有缩进问题

此外,代码中使用的变量未使用默认值定义

我在代码顶部定义了所有变量的默认值

请参阅下面的代码

         #Loop starts here
         # This one provides the option to select one of the three tasks.
 task = input (' Hello! Welcome to Patricia G. Myrons program select task 1, 2 or  3. \n')

         #If the user selects task 1, the program will perform the Simple Divisibility Test 
if task == 1  : 
  print "Task 1 is here! \n"
  print "I can tell you if n is evenly divisible by m \n"
  print "Enter the following"
  n = input("Integer:")
  m = input("Integer:")
  evaluation = n % m
if evaluation == 0:
  print n, "/", m, " evenly divides"
else:
   print n, "/", m, " Sorry, does not evenly divide. Try again!"



  #If the user selects task 2, the program will perform the Prime Test 
if task == 2 : 
   print "Task 2 is here! \n"
   print "I can tell you if the number you enter is prime or not  \n"

   number=int(raw_input("Enter a number "))
elif number <= 1:
   print "Sorry! It is not prime"
else:
   n=2
   check = True
while n != m:
    if m%n == 0:
        print "Yeas! The number you entered is prime"
        check = False
        break
    n+=1
if check == True:
        print "Yeas! The number you entered is prime" 



        #If the user selects task 3, the program will display a list of factor numbers 
if task == 3: 
        print "Task 3 is here! \n"
        print "I can tell you all of the factors of the number you enter \n"
def print_factors(n):

        print("The factors of",n,"are:")
        for i in range(1, n + 1):
  if n % i == 0:
       print(i)


   num = int(input("Enter any number: "))

请阅读,将代码缩减到最小的示例,并提供比遇到一些问题更好的问题陈述。错误是否提供完整的回溯?意外输出是否提供输入以及预期和实际输出?另外,请相应地阅读并查看缩进。@Lafada空格在Python中具有语法意义,在编辑时,您可能已删除了用户所指的问题。@jornsharpe I虽然是新用户,但不知道如何执行格式代码:@Lafada这可能也是真的@PatriciaMyron你有这么多变量问题,如果你有时间,我可以在聊天中讨论。那么OP的问题是什么?只是格式化吗?这个代码运行吗?您做了哪些更改,并解决了问题?@jornsharpe它有一些变量引用丢失和格式问题。因此,请在您的答案中包含这些信息-您更改了什么,为什么?仅使用“请尝试运行”转储固定代码并没有太大帮助。您对缩进的修改使变量的默认值完全冗余。另外,if-check==True:应该是if-check:和while:else:将完全从标志中保存您。
evaluation = 0
n = 0
m = 0
number = 0
check = False

task = input (' Hello! Welcome to Patricia G. Myrons program select task 1, 2 or  3. \n')

         #If the user selects task 1, the program will perform the Simple Divisibility Test
if task == 1  :
    print "Task 1 is here! \n"
    print "I can tell you if n is evenly divisible by m \n"
    print "Enter the following"
    n = input("Integer:")
    m = input("Integer:")
    evaluation = n % m
    if evaluation == 0:
        print n, "/", m, " evenly divides"
    else:
        print n, "/", m, " Sorry, does not evenly divide. Try again!"



#If the user selects task 2, the program will perform the Prime Test
if task == 2 :
    print "Task 2 is here! \n"
    print "I can tell you if the number you enter is prime or not  \n"

    number=int(raw_input("Enter a number "))
    if number <= 1:
        print "Sorry! It is not prime"
    else:
        n=2
        check = True
    while n != m:
        if m%n == 0:
            print "Yeas! The number you entered is prime"
            check = False
            break
        n+=1
    if check == True:
        print "Yeas! The number you entered is prime"



#If the user selects task 3, the program will display a list of factor numbers
if task == 3:
    print "Task 3 is here! \n"
    print "I can tell you all of the factors of the number you enter \n"
    def print_factors(n):

        print("The factors of",n,"are:")
        for i in range(1, n + 1):
            if n % i == 0:
                print(i)
    num = print_factors(int(input("Enter any number: ")))