随机数不会改变,重复两次

时间:2016-10-08 03:57:50

标签: python loops random

import random

def main():
    counter = StudentNames()
    StudentName = StudentNames()

    AverageRight = 0.0
    Right = 0.0

    numberone = Numbers(counter)
    numbertwo = NumbersTwo(counter)

    numberone = Equation(numberone, numbertwo)
    numbertwo = Equation(numberone, numbertwo)

    anwser = 0.0

def StudentNames():
    print("Student Name")

    StudentName = input("")
    print("Pick a Numeral Between One And Ten")

    counter = int(input(""))
    return counter
    return StudentName

def Equation(numberone, numbertwo):
    print("Enter Total [A Number Between One And Ten]")
    Total = int(input(""))

    while Total > 10:
         Total = Total + 1
         print("What Is The Answer To This Equation")
         print(numberone, "+", numbertwo)

         answer = int(input(""))
         answerOne = numberone + numbertwo

        if answer == answerOne:
            print("Correct")
            Correct = range(1, 10)
            Correct = Correct + 1
            print(Correct)
        else:
            print("Incorrect")
            incorrect = range(1, 10)
            print(incorrect)

def Numbers(counter):
    while counter > 10:
        counter = counter + 1
        numberone = random.randrange(1*2, 500*2)
        return numberone

我的随机数不会改变,除非我重新启动循环,StudentNames模块重复两次,我不明白为什么。

1 个答案:

答案 0 :(得分:0)

试试这个...你只能从一个函数返回一个值,但是你可以返回一个“元组”(一系列对象),然后以相同的方式将它拿起来:

def main():
    counter, StudentName = StudentNames()

def StudentNames():
    ... ... ...
    return counter, StudentName

对于随机数,您不需要计数器

def Numbers():
    n = random.randrange(1*2, 500*2)
    return n

并像这样调用 - 每个调用都会生成一个新的随机数

numberone = Numbers()
numbertwo = Numbers()